CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Moving a business object from a list to a new list

rated by 0 users
Answered (Verified) This post has 1 verified answer | 2 Replies | 1 Follower

Top 500 Contributor
35 Posts
Calin posted on Thu, Jul 15 2010 2:30 PM

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,

Answered (Verified) Verified Answer

Top 10 Contributor
9,270 Posts
Verified by Calin

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

All Replies

Top 10 Contributor
9,270 Posts
Verified by Calin

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

Top 500 Contributor
35 Posts
Calin replied on Fri, Jul 16 2010 1:45 AM

Thank you,

"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.

Page 1 of 1 (3 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems