Vibrant discussion about CSLA .NET and using the framework to build great business applications.
Hi,
I have a simple scenario, made it into a test so I can see it better, let me know if you need to code:
0: loadedUser.BeginEdit()
1: Vendor vendor = loadedUser.AvailableVendors[0]
2: loadedUser.AvailableVendors.Remove(vendor)
3: loadedUser.Vendors.Add(vendor).
4: loadedUser.ApplyEdit() --------->>>> Crush, Edit level mismatch.
Why does it crush ?
I've asked myself the same question for about 3 hours now, and finally stumbled on DeletedList, so if on line 2 I remove the vendor from the DeleteList then we are fine all works great.
Does anybody have a good explanation on this please ?
Thank you,
This question comes up from time to time, and I should add it to the FAQ.
The answer lies in understanding how BLB works with child objects. When you remove an object from a BLB, it isn't removed - it is marked for deletion and moved to the DeletedList. So your step 2 isn't doing what you think it does.
The easiest way to accomplish what you want is to clone the child object and add the clone to the new list, then remove the original child from the original list, and somehow make that child aware that it shouldn't actually delete itself when the original list is saved.
A more complex solution is to override the remove behavior of the original list, changing the remove behavior so it doesn't mark the child as deleted, and doesn't add it to the DeletedList. That requires a relatively deep understanding of how BLB is implemented so you can do the override without breaking the rest of the BLB behaviors.
Rocky
"The easiest way to accomplish what you want is to clone the child object and add the clone to the new list, then remove the original child from the original list, and somehow make that child aware that it shouldn't actually delete itself when the original list is saved."
This helped, I was sure that the Remove override is not the best solution.
Defenitely a FAQ subject, searched your Expert Business Object book and didn't any direct mentions on this also.