Mark Entity for deletion in Collection

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 13-Jul-2005 16:30:59   

Hi,

I use collections of entities with Infragistics grid. In this grid it's possible to delete rows. Now I want to bind my collection to this grid. When a row from the grid is deleted I want to remove the entity from my collection.

I store the collection in my session. This way I can switch between pages and the collection will still be available.

At some point I want to save my changes. Which means in this case that when I click this button I want all the removed entities from my collection to be deleted from the database. (at this point).

So I can't call the Collection.Delete method when removing them from my collection, and when I do Collection.Remove() the entity is removed and I can't delete it anymore.

How can I solve this? The problem is also that the entity being removed is an entity that was just added in memory also. And in this case it doesn't have to be removed from the database at all.

The only solution that I can think of is first delete all the rows in the table and after that add all the entities from the collection again, but this is not an ideal situation.

Can someone please advice me what to do?

Gr.,

G.I.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 13-Jul-2005 18:00:39   

You could create an array of deleted items (either the entity or just pks). Only add it to that array if the isnew property of the entity is false. Then, when the user clicks save, run thru the deleted array and delete them from the database.

hth,

Fishy

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-Jul-2005 10:12:47   

As fishy says: create a collection for deleted items, and then add it to a unitofwork object. The UnitOfWork object is clever enough to ignore new entities when you want to delete them, so just pass it to the unitofwork object and it will be ok simple_smile

Frans Bouma | Lead developer LLBLGen Pro