DeleteEntityCollection isn't deleteting

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 28-Sep-2010 14:31:53   

I have this piece of code:


 public int DeleteProfiles(IList<decimal> idsToDelete)
 {
            IEntityCollection2 entitiesToDelete = new EntityCollectionNonGeneric();

            foreach (decimal id in idsToDelete)
            {
                entitiesToDelete.Add(new XpTabulkyGridEntity(id));
            }

            using (var factory = this.configRepositoryFactory())
            {
                return factory.Value.DeleteCollection(entitiesToDelete);
            }
   }


and the DeleteCollection method


 public int DeleteCollection(IEntityCollection2 collection)
 {
          return this.adapter.DeleteEntityCollection(collection);
 }

There is no error showing up but also no sql query is hitting the DB.

Runtime library version: 2.6.10.0526

and I'm using the ODT.NET provider.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Sep-2010 21:33:07   

Does enabling LLBLGen's debug tracing (http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_troubleshootingdebugging.htm) give you any more clues as to what is going on...? You should be able to see if it thinks it is generating SQL Delete statements.

Another option would also be to use "DeleteEntitiesDirectly" as it has a lower overhead in terms of Entity creation, and so should perform better.

Matt

methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 29-Sep-2010 10:21:03   

Ok will try the "DeleteEntitiesDirectly" method but anyway I'd like to figure out what's wrong.

This is what i got from the output:


Method Enter: DataAccessAdapterBase.DeleteEntityCollection
Method Enter: UnitOfWork2.Commit(2)
Method Enter: DataAccessAdapterBase.StartTransaction
Method Enter: DataAccessAdapterBase.OpenConnection
Method Exit: DataAccessAdapterBase.OpenConnection
Method Exit: DataAccessAdapterBase.StartTransaction
Method Enter: DataAccessAdapterBase.PersistQueue
Method Exit: DataAccessAdapterBase.PersistQueue
Method Enter: DataAccessAdapterBase.PersistQueue
Method Exit: DataAccessAdapterBase.PersistQueue
Method Enter: DataAccessAdapterBase.Commit
Method Exit: DataAccessAdapterBase.Commit
Method Exit: UnitOfWork2.Commit(2)
Method Exit: DataAccessAdapterBase.DeleteEntityCollection

No SQL query were generated..

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Sep-2010 11:23:21   

Entities should be fetched before deleting them using DeleteEntityCollection(). Otherwise use DeleteEntitiesDirectly(). I'm trying to reproduce it.

I don't know why I haven't seen this way earlier.

Anyway, passing the PK value in the CTor doesn't actually set the PK field value. This is only used for fetch purposes.

You need to do something like:

public int DeleteProfiles(IList<decimal> idsToDelete)
{
            IEntityCollection2 entitiesToDelete = new EntityCollectionNonGeneric();

            foreach (decimal id in idsToDelete)
            {
                var xp = new XpTabulkyGridEntity();
                xp.Id = id;
                xp.IsNew = false;
                entitiesToDelete.Add(xp);
            }

            using (var factory = this.configRepositoryFactory())
            {
                return factory.Value.DeleteCollection(entitiesToDelete);
            }
}
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 29-Sep-2010 12:07:20   

Thank you forthe explanation. I will use the DeleteEntitiesDirectly method.