Validation-Performance

Validation-Performance

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


haripriya_kumar posted on Monday, March 24, 2008

I have a collection, each object in it has validation setup as AddInstanceBusinessRules or AddBusinessRules. I don't want the object to be validated if its a load, is there any way I can prevent the validation through CSLA methods available during load........ Yes I can check if its a load or not but i don't want to hit the AddInstanceBusinessRules or AddBusinessRules methos at-all during load.

JohnB replied on Tuesday, March 25, 2008

I'm not really sure if that is the best thing to do. I would suggest that you just skip the call to ValidationRules.CheckRules() when the object is created.

The setup of the business rules should not have any effect on your performance but calling CheckRules() could.

HTH,
John

RockfordLhotka replied on Tuesday, March 25, 2008

You can't avoid having AddInstanceBusinessRules() called for each instance - if you don't want per-instance rules then don't override this method.

The AddBusinessRules() method is called once per appdomain, not once per object. So it is not called on every object you create.

The actual checking of rules is caused by a call to ValidationRules.CheckRules(). If you don't want the rules checked when your object is created/loaded then don't call this method in the DataPortal_XYZ method.

In CSLA .NET 3.5 there's a protected SuppressRuleChecking property you can set to true to stop CheckRules() from doing any work. This is designed to allow you to create batch load scenarios for an object, where you set a whole bunch of properties and then manually call CheckRules() at the end of the process. I don't think this is useful for your scenario, but I thought I'd mention it just in case.

JonnyBee replied on Wednesday, March 26, 2008

And in the DataPortal_XYZ methods you should set the internal variables rather than public properties to avoid calling "PropertyHasChanged" which will execute the validation rules for that property/dependant properies.


Copyright (c) Marimer LLC