Should we trust the database?

Should we trust the database?

Old forum URL: forums.lhotka.net/forums/t/4971.aspx


nelis posted on Friday, June 13, 2008

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?

ajj3085 replied on Friday, June 13, 2008

Well, there's really no hard and fast rule.  The PTracker does trust the database, or it would call checkrules.  Of course, it's also a sample, so not everything is demonstrated.

In my environment, I am the one in charge of the database... so I decide who can access it and how.  As it stands, the only way into my database is through my application.. so my application trusts the data.  Your situtation may be different though.

JoeFallon1 replied on Friday, June 13, 2008

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

 

sergeyb replied on Friday, June 13, 2008

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

 



JonM replied on Tuesday, June 17, 2008

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