Somewhere - I think it was in the book - I read that we should not trust the data in the database to represent valid object. That's because it can be updated by other tools than your application.
If you adopt to that philosophy, I would expect ValidationRules.CheckRules being called in the various Fetch_Xxx routines. I do not find such a thing in the ProjectTracker example. Am I wrong or is the PT application simply trusting the database?
I do not trust the database and therefore call ValidationRules.CheckRules as the final block of code in both DataPortal Create and Fetch.
YMMV
Joe
I agree that validation rules should be called on create.
Fetch to me required other considerations. If data that comes from DB is
invalid, you end up with non-dirty object that is invalid. So, if the
user does not change something, he/she is not forced to correct the problem
anyway. So, I personally do not call validation rules after fetch.
If data got into DB and was valid at that point, it should be valid when you
fetch it as well. If rule changed since the data was saved last, there
should have been script run on DB to bring old data into compliance with new
rules.
Just my thoughts on the subject…
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Magenic ®
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: JoeFallon1
[mailto:cslanet@lhotka.net]
Sent: Friday, June 13, 2008 10:52 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Should we trust the database?
I do not trust the database and therefore call ValidationRules.CheckRules as
the final block of code in both DataPortal Create and Fetch.
YMMV
Joe
If other applications are directly changing your underlying database then validation on load makes sense. The problem I've seen with this is that you will take a significant performance hit especially if you have custom validation rules. Its not a big deal to run a validation rule on a single object when it changes. It can be a big deal to run every validation rule on every object depending on the size of your collection.
Copyright (c) Marimer LLC