how to manipulate with a sub EntityCollection

Posts   
 
    
dkunstek
User
Posts: 7
Joined: 27-Mar-2008
# Posted on: 27-Mar-2008 10:45:50   

Hello,

I have an entity that has a collection of child entites: PriceListEntity with a collection of PriceItem entities.

Through code, I'm manipulating with a PriceItemEntity subcollection and i came across the following "problem":

Some new entities are added using priceListEntity.PriceItem.AddNew() and then later the same new entities are removed using priceListEntity.PriceItem.Remove(...) methods. After that a save operation is executed via adapter's SaveEntity(priceListEntity) method. Save operation inserts ALL the PriceItem entities that were added via AddNew() method although some of those entities were removed before saving. The collection doesn't contain these "new-removed" entities but still they are inserted into DB.

Can you please explain this strange behavior?

Thanks, d.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 28-Mar-2008 11:16:20   

Please don't use AddNew() it's for databinding code only as the reference manual says.

Do not call this method from your own code. This is a databinding ONLY method.

Also please post a code snippet.

dkunstek
User
Posts: 7
Joined: 27-Mar-2008
# Posted on: 28-Mar-2008 11:37:22   

Walaa wrote:

Please don't use AddNew() it's for databinding code only as the reference manual says.

I tried to do it also like this:

// adding of new entities PriceEntity price = new PriceEntity(); _priceList.Price.Add(price);

Later in my code, i removed some newly added entites like this:

if(price.IsNew) // business rule doesn't allow removing already persisted price items _priceList.Price.Remove(price);

After the removal, debuger shows that _priceList.Price.Count is correct. Now i tried to persist the _priceList object like this:

adapter.SaveEntity(_priceList);

All new entities that i added end up inserted in DB. How is that possible if i detached them with Remove() method and Count value is correct? Where are these removed entities hidden and why are they inserted into DB?

thanx, daniel

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Apr-2008 05:37:19   

Hi Daniel,

Please read this thread and make sure you don't have that problem: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6608&StartAtMessage=0&#36475

Also please post your LLBLGenPro version and runtime library version (http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7718)

adapter.SaveEntity(_priceList);

Are you saving like that or recursively?

BTW: sorry for the late response, next time please post at GenertaedCode or BugAndIssues forums, as this isn't an architecture thread directly simple_smile

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 07-Apr-2008 11:45:47   

I think this is an older bug fixed in a later build of the runtime library.

Shall I move the thread to general?

Frans Bouma | Lead developer LLBLGen Pro