Initial Rule Check

Initial Rule Check

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


t.kehl posted on Saturday, August 21, 2010

Hi.

I am working with CSLA.NET 4. Now I have the fallowing problem:

I have a EditableRootObject which has several Rules. In the Fetch-Method, I load the properties with the LoadProperty()-Method. I have now seen, that this not check the rules that they are inital broken (when no value is set and there is a Required-Rule). Know my question: Should I load all values with SetProperty()? - Or is there another way, that the Rules are initial broken?

Thanks for your help.

Best Regards, Thomas

RockfordLhotka replied on Saturday, August 21, 2010

Just call BusinessRules.CheckRules() at the bottom of your fetch method.

CSLA does this for you after the create method completes - because you almost always want to check the rules for a new object. But it doesn't do this by default for a fetch, because many applications implicitly trust whatever data they just got from the database and running the rules would be unnecessary overhead.

However, it is also quite common to need the rules to run at the end of a fetch - and so you can just call BusinessRules.CheckRules() to make that happen.

Copyright (c) Marimer LLC