DataScope change uow Work Order for deletes when using a unique constraint

Posts   
 
    
Puser
User
Posts: 228
Joined: 20-Sep-2012
# Posted on: 02-Jun-2023 11:40:42   

Hi,

I have an entity Uitgave with a list of related entities of UitgaveTrede (pk UitgaveId). UitgaveTrede also has a unique constraint on two other fields (BovenTrede, ContractTypeId). The Uitgave with UitgaveTredes are fetched in UitgaveEntity (with the related entities on navigator/relationship UitgaveTredes) These are attched to a new DataScope scope.Attach(uitgave); The (list of) UitgaveTredes are now updated, items deleted, items added. When calling CommitChangesAsync I get an exception

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: 'An exception was caught during the execution of an action query: Cannot insert duplicate key row in object 'dbo.UitgaveTrede' with unique index 'BovCon'. The duplicate key value is (2000,1).

This is because the work order is inserts and then deletes. In a UnitOfWork I can change the order, but in a DataScope it is fixed and _uowWorkOrder is private

        private List<UnitOfWorkBlockType> _uowWorkOrder;

And cannot be set.

Also, overriding protected virtual IUnitOfWorkCore BuildWorkForCommit() does not work because I cannot access _context:

        protected virtual IUnitOfWorkCore BuildWorkForCommit()
        {
            return _context.CreateFilledUnitOfWork(this, _uowWorkOrder, _refetchStrategy);
        }

Is there a work around by using the uow from BuildWorkForCommit()* directly and setting its CommitOrder (to set the deletes first and so on)? Are there any pitfalls by using this uow directly and/or do I have to do some extra work to make it work exactly as the CommitChangesAsync in the DataScope?

  • I'm already using an inherited class of DataScope for some upfront checks and loggings where I also use this BuildWorkForCommit() upfront, so I already have access to the uow.

Thanks

Using 5.9 (5.9.3) RTM with adapter and Sql Server

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39625
Joined: 17-Aug-2003
# Posted on: 02-Jun-2023 14:51:37   

In your override of BuildWorkForCommit, call the base method, you get a UnitOfWork2 back. This has a property, CommitOrder, this is the actual commit order of the unit of work, you can change the list's contents and it'll be used at commit simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Puser
User
Posts: 228
Joined: 20-Sep-2012
# Posted on: 02-Jun-2023 15:05:56   

Thanks!

And the RefetchStrategy on the DataScope will be respected?

Walaa avatar
Walaa
Support Team
Posts: 14954
Joined: 21-Aug-2005
# Posted on: 02-Jun-2023 15:47:14   

The RefetchStrategy is set per DataScope, it's a property in the DataScope class.