Deleting entities based on IEnumerable

Posts   
 
    
rboarman
User
Posts: 83
Joined: 01-Feb-2005
# Posted on: 13-Mar-2012 01:18:43   

I am using version 3.1 Final dated 2/22/2012 in adapter mode.

I am trying to write a generic method to remove entities based on a list of entities.

        public void Delete<T>(IEnumerable<T> entites) where T : class, new()
        {
            var q = entites.AsQueryable();
            var col = ((ILLBLGenProQuery)q).Execute() as IEntityCollection2;
            this.Adapter.DeleteEntityCollection(col);
        }

The above Execute call is not working. I get this exception:

Unable to cast object of type 'System.Linq.EnumerableQuery`1[BidService.Server.Db.Llbl.Generated.EntityClasses.BidEntity]' to type 'SD.LLBLGen.Pro.LinqSupportClasses.ILLBLGenProQuery'.

What did I do wrong?

Thank you.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Mar-2012 06:33:26   

DataAccessAdapter.DeleteEntityCollection receives an IEntityCollection2. Also, the linq query you are running won't work because you are not specifying any metaData (See the LINQ2LLBL usage.

You have 2 options:

  1. Outside that method, fetch the collection and pass it (IEntityCollection2) to your method, where you can delete it. See more about deleting collections.

  2. Iterate into the collection to obtain the PK, then build a list of PKs, then you can write a FieldCompareRangePredicate and pass it to an adapter.DeleteEntitiesDireclty.

David Elizondo | LLBLGen Support Team