Related entity validated even though removed from collection

Posts   
 
    
zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 03-Jun-2009 10:51:11   

I have an entity which has a 1-to-many relation with an another one.

Eg. Member -> ChildMember

At some point I create a ChildMember and add it to Member.Children collection and do some other stuff. If the procedure does not complete properly I remove the Child from Member.Children.

All is fine until I save the Member instance specifying to do a recursive save. What happens is that during the save the child member, which has been removed from the Children collection, is still validated, and I imagine that if validation passes it would also saved. Why is this? It's been removed from Member so it should not be used anymore.

I'm using SelfServicing, LLBLGen version 2.6 6th June 2008.

Thanks for the help

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 03-Jun-2009 10:58:40   

Are you sure when saving the Member.Children collection doesn't contain that specific entity?

Please post some code snippets, for adding the Child to the member and for removing it.

zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 03-Jun-2009 11:10:47   

Walaa wrote:

Are you sure when saving the Member.Children collection doesn't contain that specific entity?

Please post some code snippets, for adding the Child to the member and for removing it.

I'm 100% sure, I checked the children collection and the Count is 0 so I'm sure it's not there.

Code snippet:

dim child as new ChildEntity
child.Validator = new ChildValidator
child.Parent = _member

do some stuff..... and if if have to cancel the whole thing:

child.Parent = nothing (I event tried _member.Children.Remove(child)

_member.Save(nothing,true)
zulu
User
Posts: 50
Joined: 25-Aug-2008
# Posted on: 03-Jun-2009 11:14:42   

Actually it hit me just now.. The child member is linked to the parent member in more than a way (Child.Parent, Child.Sponsor), so I was removing one link but not another...

Sorry to have wasted your time.. but I couldn't see it until now.

Thanks