Business rule in Collection objectBusiness rule in Collection object
Old forum URL: forums.lhotka.net/forums/t/3392.aspx
ravimaran posted on Thursday, August 16, 2007
Hi, I am totally new in using CSLA.NET frame work. I am building this windows app. and I have list of child objects which needs to compared when a new child object is added to the collection. I implemented the rule in the child object and when new child is called i am getting error: null exception of parent. I understand that when new child is created its parent will be null till it is added to the collection (parent). How could let the child know the parent object? or are there other alternatives for this problem?
Thank you
richardb replied on Tuesday, August 28, 2007
You could use the Contains method in the BO Child Collection. You can overload the method and change it to compare the child you are about to add with the children currently in the collection - perhaps on ID or some other criteria.
You could have an additional method on your parent object which lets you AddChildren and flags a problem to your UI if there is a matching child object already. Or in the Add method on the collection put the code there to check for existing children, returning nothing if it fails to be added.
Copyright (c) Marimer LLC