Hi guys.
I have seen similar posts to this but no definitive answer. Say you have a collection that contains child objects and you add several children before calling save. What if one of those children violates a business rule? You get an "Object is not valid and cannot be saved" exception but how can you tell the user why the object is not valid? The collection will have an empty BrokenRulesCollection and it seems the only way to know what the broken rule is and indeed which object is breaking it is to use the debugger - obviously not possible on a user's pc.
How have other people soleved this problem? I tried to work out a way to look at the object's properties, determine which were business objects and check their BrokenRulesCollection properties too but it got really messy, especially when children had child collections themselves!
Any help or advise with this would be great. This is more of a problem in the web, as I can use an errorprovider and datagridview with a windows form.
John.
For the web ui... could you loop thru all the child collections checking for invalid children and grab the broken rules for each child?
I haven't touched validation yet so it's only a guess :)
This is a reply to both Brian and RangerGuy.
Yes you can loop thru an object and display the child broken rules in a treeview or otherwise, but the key here is that you would have to code this functionality for every collection object i.e. I have not found a way to generically do this for all objects and show broken rules in a single dialog box. That is the real problem!
Brian
That is what I tried to do but struggled. Do you have any code you could post to do this?
TIA
To each of my Objects and Collections I have added:
Public ReadOnly Property BrokenRulesString() as String
Get
' Use a StringBuilder to Concatenate all BrokenRulesStrings from all Children
End Get
End Property
If a Collection is not valid, I call its BrokenRulesString to get a listing of broken rules of all its children. Each object identifies itself in the list of broken rules it sends back, and also inserts line breaks etc as needed. Empty String comes back if no rules are broken.
Jav
Copyright (c) Marimer LLC