BrokenBusinessRules for BusinessListBase #3438
-
I have to 'batch' save a collection (read-write) where the child object(s) has business/validation rules. var allRules = BusinessRules.GetAllBrokenRules(colllineitems); Kind Regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It depends on what you need to show the user. A simple I see a challenge here, in that the For example, define a public class MyBrokenRule
{
public MyBrokenRule(MyChild child, Csla.Rules.BrokenRule rule)
{
ContainingObject = child;
BrokenRule = rule;
}
public MyChild ContainingObject { get; set; }
public Csla.Rules.BrokenRule BrokenRule { get; set; }
} Then add this to the list class: public List<MyBrokenRule> GetBrokenRules()
{
var result = new List<MyBrokenRule>();
foreach (var item in this)
{
foreach (var rule in item.GetBrokenRules())
{
result.Add(new MyBrokenRule(item, rule));
}
}
return result;
} Then your calling code can display the broken rules for all children, with info about each child like this: var rules = list.GetBrokenRules();
foreach (var rule in rules)
Console.WriteLine($"{rule.ContainingObject}, {rule.BrokenRule}"); |
Beta Was this translation helpful? Give feedback.
-
@rockfordlhotka Thank you Sir. |
Beta Was this translation helpful? Give feedback.
It depends on what you need to show the user.
A simple
foreach
loop through the child objects allows you to callGetBrokenRules
on each and build a list of all the broken rules.I see a challenge here, in that the
BrokenRule
type doesn't keep track of the object it pertains to, so you can't tell the user which object corresponds to each broken rule without doing that work yourself. You could solve that in a number of ways if that information is relevant.For example, define a
MyBrokenRule
class: