How do I use a transaction to delete an entity collection based on a filter?

Posts   
 
    
djmarkert
User
Posts: 4
Joined: 23-Nov-2004
# Posted on: 01-Mar-2005 21:11:28   

Otis,

I would like to use a native database transaction to delete a number of entities based on a filter (these entities are represented by a single table, with no FK references). I was previously calling collection.DeleteMulti(filter) when I wasn't using transactions, but now I need to delete the items as part of a transaction.

Is the best way to do what I want to do something like this?:


MyCollection collection = new MyCollection ();
IPredicateExpression filter = some filter code...           
collection.GetMulti(filter);
foreach(MyEntity entity in collection)
{
    transaction.Add(entity);
    entity.Delete();
}

Dave

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Mar-2005 21:14:55   

Add the collection to the transaction, then call DeleteMulti(filter).

Frans Bouma | Lead developer LLBLGen Pro