Detecting pending deletes within related entity collection

Posts   
 
    
chrishilton avatar
Posts: 49
Joined: 26-Jun-2007
# Posted on: 11-Sep-2007 22:07:27   

I'm using LLBLGen Pro 2.0.0.0 Final with adaptor and .NET 2.0/c# connecting to a SQL Server 2005 dB.

I've written my own IsDirty method to call before an application screen is closed so that I can warn the user if there are any outstanding changes to the main entity or any of its related entities. This works a treat when inserting/updating but can anyone tell me how to detect a pending delete if an entity has been removed from a related entity collection?

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 11-Sep-2007 22:23:02   

Maybe looking at the Fields.State property of an entity within the entitycollection ? So for every dirty entity within the collection where the Fields.State = EntityState.Deleted, you could assume it has been deleted...

grtz, Danny

chrishilton avatar
Posts: 49
Joined: 26-Jun-2007
# Posted on: 12-Sep-2007 00:16:29   

Thanks for the suggestion Danny but in my case the entity will have been removed from the entity collection so I won't be able to check its properties.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 12-Sep-2007 12:19:33   

Note: Removing an entity from a collection doesn't necessarily mean it should be deleted from the databse.

In your case you may maintain a parallel collection only for deleted entities, so when you remove an entity from the main collection, add it to the to-Be-Deleted collection, and in your IsDirty method, you may check on the count of the to-Be-Deleted collection.

You may also a Unit of Work.