Validation Rule Groups

Validation Rule Groups

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


xAvailx posted on Wednesday, October 21, 2009

Is there a way to specify a set of validations to be validated together?

The scenario I have is I have about 8 validation rules that need to be triggered based on the state of an object. I would like to do something like

CheckRules.Validate("MyGroup") and it would validate only those 8 rules.

sergeyb replied on Wednesday, October 21, 2009

You should probably use ValidationRules.AddDependantProperty to tie different properties's validation together. You could also just call ValidationRules.CheckRules() to run all the rules in your class.

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

-----Original Message-----
From: xAvailx [mailto:cslanet@lhotka.net]
Sent: Wednesday, October 21, 2009 7:29 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Validation Rule Groups

Is there a way to specify a set of validations to be validated together?

The scenario I have is I have about 8 validation rules that need to be triggered based on the state of an object. I would like to do something like

CheckRules.Validate("MyGroup") and it would validate only those 8 rules.

xAvailx replied on Thursday, October 22, 2009

Thanks Sergey, I guess the issue I saw with using a dependent property is the state that triggers these changes come from the parent class.

Is there a way to create a dependent property with no related object property? I think that would solve my issue.

My question is related to this post:

http://forums.lhotka.net/forums/thread/37341.aspx

Thx.

JonnyBee replied on Thursday, October 22, 2009

Hi,

I agreee with Sergey that you should look at AddDependentProperty and I 'd prefer to define these as DependentProperties as depedent between properties in your BO.

However - a DependentProperty can also be what you described as a Group that does not have to be an actual implemented property in the BusinessObject.

Ex:
ValidationRules.AddDependentProperty("property1", "group1", true);
ValidationRules.AddDependentProperty("property2", "group1", true);
ValidationRules.AddDependentProperty("property3", "group1", true);


And you could then call:
ValidationRules.CheckRules("group1");

xAvailx replied on Thursday, October 22, 2009

I think this is what I am looking for. See my reply to Sergey regarding further explanation of my scenario. I will give this a shot. Thx!

Copyright (c) Marimer LLC