Question RE: UnitOfWork.AddDeleteMultiCall

Posts   
 
    
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 12-Oct-2005 01:49:44   

Hi there,

I need to delete a few entities directly from the dB (not loading first) and am having trouble understanding how to do this. I have a UnitOfWork object involved, and I saw the AddDeleteMultiCall, and thought to use it. I am using the following code:

uow.AddDeleteMultiCall(new ContributionsCollection(),PredicateFactory.CompareValue( ContributionsFieldIndex.CommitteeID,ComparisonOperator.Equal,(int)this.data.Tag2));

This gives me an exception about a missing relationWalk object. confused

What is the proper way to accomplish a direct delete of some entities using a UnitOfWork object?

Thanks, Josh

Paul.Lewis
User
Posts: 147
Joined: 22-Aug-2005
# Posted on: 12-Oct-2005 04:40:00   

tomahawk wrote:

Hi there,

I need to delete a few entities directly from the dB (not loading first) and am having trouble understanding how to do this. I have a UnitOfWork object involved, and I saw the AddDeleteMultiCall, and thought to use it. I am using the following code:

uow.AddDeleteMultiCall(new ContributionsCollection(),PredicateFactory.CompareValue( ContributionsFieldIndex.CommitteeID,ComparisonOperator.Equal,(int)this.data.Tag2));

This gives me an exception about a missing relationWalk object. confused

What is the proper way to accomplish a direct delete of some entities using a UnitOfWork object?

Thanks, Josh

Josh,

I'm not seeing anything wrong with your statement. However, try this and see if it makes any difference:

ContributionsCollection Contributions = new ContributionsCollection();
IPredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareValue(ContributionsFieldIndex.CommitteeID,ComparisonOperator.Equal,(int)this.data.Tag2));
uow.AddDeleteMultiCall(Contributions, filter);
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 12-Oct-2005 06:54:03   

Same result, which is a TargetInvocationExeption with message "relationsToWalk can't be null." when I attempt to commit the UnitOfWork.

tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 12-Oct-2005 08:28:36   

So I got it to work by building a relation set. But now I have a different problem. I am running the UnitOfWork in an routine that updates the database, so I need everything to be contained in that UnitOfWork. In the routing, the code is adding/updating some entities, deleting others. I add the AddDeleteMultiCall, do some more work, then commit the UOW. Problem is, it seems like the DeleteMulti is ocurring after all the adds, and it deletes some of the added entities, as they are related. I need the delete to happen first, then all the adds.

Any advice?

-Josh

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Oct-2005 10:24:27   

tomahawk wrote:

So I got it to work by building a relation set. But now I have a different problem. I am running the UnitOfWork in an routine that updates the database, so I need everything to be contained in that UnitOfWork. In the routing, the code is adding/updating some entities, deleting others. I add the AddDeleteMultiCall, do some more work, then commit the UOW. Problem is, it seems like the DeleteMulti is ocurring after all the adds, and it deletes some of the added entities, as they are related. I need the delete to happen first, then all the adds.

Any advice? -Josh

That can't be done, the right order to avoid any problems is: insert, update, delete. So deletes are always done, in ONE UoW, after the updates.

If you want to execute teh deletes first, use 2 UoW's.

Frans Bouma | Lead developer LLBLGen Pro
tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 12-Oct-2005 10:49:02   

I'll just use the 2 uow's then. Thanks for the quick responses.