The business rules are not being enforced in my business object. Here is an example of the property declaration:
private static PropertyInfo<string> ShortNameProperty = RegisterProperty(new PropertyInfo<string>("relLoc"));
public string ShortName
{
get { return GetProperty<string>(ShortNameProperty); }
set { SetProperty<string>(ShortNameProperty, value); }
}
And here is the rule declaration:
ValidationRules.AddRule(Csla.Validation.
CommonRules.StringRequired, new Csla.Validation.RuleArgs(ShortNameProperty));ValidationRules.AddRule(Csla.Validation.
CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs(ShortNameProperty, 4));When CommonRules tries to evaluate this rule it calls a Utility class called CallByName which executes this code which results in null:
PropertyInfo p = target.GetType().GetProperty(methodName);
where target is my business object and methodName = "relLoc".
The next line creates a null exception and exits the the whole process:
return p.GetValue(target, args);
The rest of the processing does't happen and the object remains valid and allows Save to be called.
Any idea of what I did wrong?
Todd
Your
property is not declared properly. Parameter for new ProeprtyInfo should
be actual property name as in
private static PropertyInfo<string>
ShortNameProperty = RegisterProperty(new PropertyInfo<string>("ShortName"));
public string ShortName
{
get { return GetProperty<string>(ShortNameProperty); }
set { SetProperty<string>(ShortNameProperty,
value); }
}
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: thaehn
[mailto:cslanet@lhotka.net]
Sent: Thursday, April 16, 2009 1:47 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Error in CommonRules - Utilities Class
The business rules are not being enforced in my business object. Here
is an example of the property declaration:
private static PropertyInfo<string>
ShortNameProperty = RegisterProperty(new PropertyInfo<string>("relLoc"));
public string ShortName
{
get { return GetProperty<string>(ShortNameProperty); }
set { SetProperty<string>(ShortNameProperty,
value); }
}
And here is the rule declaration:
ValidationRules.AddRule(Csla.Validation.CommonRules.StringRequired, new Csla.Validation.RuleArgs(ShortNameProperty));
ValidationRules.AddRule(Csla.Validation.CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs(ShortNameProperty, 4));
When CommonRules tries to evaluate this rule it calls a Utility class called
CallByName which executes this code which results in null:
PropertyInfo p = target.GetType().GetProperty(methodName);
where target is my business object and methodName = "relLoc".
The next line creates a null exception and exits the the whole process:
return p.GetValue(target, args);
The rest of the processing does't happen and the object remains valid and
allows Save to be called.
Any idea of what I did wrong?
Todd
Sergey,
The name of the column in the database is "relLoc", but the property name is "ShortName". Do they have to be the same? Do I need to change "ShortName" to "relLoc"?
Todd
Copyright (c) Marimer LLC