Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> Cannot Batch-delete using UnitOfWork & adapter.BatchSize
 

Pages: 1
Bugs & Issues
Cannot Batch-delete using UnitOfWork & adapter.BatchSize
Page:1/1 

  Print all messages in this thread  
Poster Message
HcD
User



Location:
Belgium
Joined on:
12-May-2005 00:02:28
Posted:
214 posts
# Posted on: 17-Jul-2019 13:30:08.  
(Using LLBLGen 5.5.1, Adapter templates & SQL Azure)

Hi,
I'm building in the adapter.BatchSize feature to speed up some of our queries.
In our system we have an entity called "WorkingCopy" and sometimes we need a lot of these entities to work on, save them and delete them.

I've seen a great increase in speed our Save routine by using a UnitOfWork2, adding the WorkingCopyEntity's with uow.AddForSave and then set the adapter.BatchSize to 50 before doing the uow.Commit. It's 3x faster than using adapter.SaveEntityCollection !

But for the delete, it just does't work. Nothing gets deleted.

This was the original routine :

Code:
        public override void Remove(IEnumerable<int> workingcopyIds)
        {
            using (var adapter = CreateAdapter())
            {
                foreach (var workingcopyId in workingcopyIds)
                {
                    var entity = new WorkingCopyEntity(workingcopyId);
                    adapter.DeleteEntity(entity);
                }
            }
        }


which works, but obviously is very slow.

I have tried both the AddForDelete or AddcollectionForDelete of the UnitOfWork, and both don't do anything :

Code:
        public override void Remove(IEnumerable<int> workingcopyIds)
        {
            var list = workingcopyIds.ToList();
            var uow = new UnitOfWork2();
            EntityCollection<WorkingCopyEntity> coll = new EntityCollection<WorkingCopyEntity>();
            foreach (var workingcopyId in workingcopyIds)
            {
                var entity = new WorkingCopyEntity(workingcopyId);
                uow.AddForDelete(entity);
            }
            using (var adapter = CreateAdapter())
            {
                adapter.BatchSize = 50;
                uow.Commit(adapter, true);
            }
        }


or

Code:
        public override void Remove(IEnumerable<int> workingcopyIds)
        {
            var list = workingcopyIds.ToList();
            var uow = new UnitOfWork2();
            EntityCollection<WorkingCopyEntity> coll = new EntityCollection<WorkingCopyEntity>();
            foreach (var workingcopyId in workingcopyIds)
            {
                var entity = new WorkingCopyEntity(workingcopyId);
                coll.Add(entity);
            }
            uow.AddCollectionForDelete(coll);
            using (var adapter = CreateAdapter())
            {
                adapter.BatchSize = 50;
                uow.Commit(adapter, true);
            }
        }


It does nothing. No error, no output logging when setting the web.config value SqlServerDQE to 4 ... just nothing.

What am I doing wrong ?

Kind regards,
Sven.
rock on ! 8)  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37546 posts
# Posted on: 17-Jul-2019 15:11:14.  
The batching facility is for inserts/updates only at the moment, so deletes aren't batched. So it's indeed not going to work: it's not built-in at the moment.

Are there criteria you can use to delete them with a direct delete on the database instead? You can use these calls in a Uow as well.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
HcD
User



Location:
Belgium
Joined on:
12-May-2005 00:02:28
Posted:
214 posts
# Posted on: 17-Jul-2019 15:15:31.  
Well, I have the list of Ids that need to be deleted ....
rock on ! 8)  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14495 posts
# Posted on: 17-Jul-2019 23:02:30.  
The best way is to execute the delete directly against the database without creating or fetching entities.
Code:
var bucket = new RelationPredicateBucket(CustomerFields.CustomerID.In(IDs) ); // IDs is int[] in this case.
using(var adapter = new DataAccessAdapter())
{
    adapter.DeleteEntitiesDirectly("CustomerEntity", bucket);
}

using UnitOfWork:
Code:
uow.AddDeleteEntitiesDirectlyCall("CustomerEntity", bucket);


  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.