How do you delete a List of Entities?

Posts   
 
    
BringerOD
User
Posts: 70
Joined: 15-Jul-2006
# Posted on: 16-Mar-2008 02:36:23   

How do you delete the entities after you retrieve them using linq?

I am sure I can loop throug the collection but I would prefer to delete them all at once.

I am sure this is easy at the moment I can't figure it out.

 var linqMetaData = new LinqMetaData(dataAccessAdapter);
 var q = linqMetaData.EntityIndex;
 dataAccessAdapter.DeleteEntityCollection((IEntityCollection2)q.ToList());

rage

Noob questions. Sorry.

Bryan

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Mar-2008 10:35:39   

When you call ToList(), it creates a List<entity> collection, it has to, ToList forces it to do that.

However as you expect: this is a copy action. So instead do: var q = ... IEntityCollection2 col = ((ILLBLGenProQuery)q).Execute();

simple_smile

(from my bare head so can have some typo's but the idea is to cast the q to an ILLBLGenProQuery simple_smile

You can also traverse the List<T> yourself of course and call adapter.DeleteEntity() with the entity, first starting a transaction before you traverse the list.. Though that's less efficient.

Frans Bouma | Lead developer LLBLGen Pro
BringerOD
User
Posts: 70
Joined: 15-Jul-2006
# Posted on: 16-Mar-2008 18:18:43   

That was it! Was not making the connection in my head that the result could be cast to something other then what it was. Make sense now.