CallBack and UnitOfWork

Posts   
 
    
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 06-May-2015 17:55:40   

Using self servicing and version 4.2

Your examples show using callbacks that do not have a transaction parameter as the last parameter:

// C#
UnitOfWork uow = new UnitOfWork();
uow.AddCallBack(new ActionProcedures.ClearTestRunDataCallBack(ActionProcedures.ClearTestRunData), 
    UnitOfWorkCallBackScheduleSlot.PreEntityDelete, true, _testRunID);

The generated call back routines that I get DO have Transaction as the last parameter.

1) Should I pass null into the 'CallBack' for the transaction and when UoW makes the call it will provide the real transaction (if true is passed in for use transaction)? 2) Why do your examples and in the forum show use of the CallBack where a transaction is not provided - meaning the code generated is different than what I get?

Posts: 1255
Joined: 10-Mar-2006
# Posted on: 06-May-2015 18:00:02   

Grrr...misreading the docs, over and over again... Never mind....dunno what I was thinking....

The real problem is the ActionProcedure has ref parameters, which you cannot use on params. So not sure what to do.

Maybe you could consider a simple lambda expression to be provided as the callback - you can provide the transaction object as a parameter...then we dont need code generated or anything.

Posts: 1255
Joined: 10-Mar-2006
# Posted on: 06-May-2015 18:01:57   

Maybe:


unitOfWork.AddCallBack(UnitOfWorkCallBackScheduleSlot.PostEntityDelete,
   trans=> ActionProcedures.MyProc(2,34,3,trans) );

That would be much simpler to use and resolve my ref issue...

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 07-May-2015 00:14:48   

You can use your own delegate and method in which you call the SP. Example here: https://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=20782&StartAtMessage=0&#117091

Posts: 1255
Joined: 10-Mar-2006
# Posted on: 11-May-2015 16:44:31   

Right. Delegates - completely unused anywhere now that we have lambdas!

Feature request - can you please add/forward to team?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-May-2015 09:33:08   

the delegates are predefined, and I don't see why they are so horrible to use?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 1255
Joined: 10-Mar-2006
# Posted on: 12-May-2015 14:45:39   

It is just much easier to use the lambdas. With the introduction of Lambdas no one uses or needs delegates anymore.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-May-2015 17:23:29   

WayneBrantley wrote:

It is just much easier to use the lambdas. With the introduction of Lambdas no one uses or needs delegates anymore.

No that's not true. Delegates are often used in apis, as they dictate method signatures. The thing is that with ref parameters, the value returned has to end up somewhere, and a lambda doesn't cut it, as where is the value going? So you have to supply your own method which calls the proc.

Anyway, delegates and lambda's are close friends simple_smile I can do this:

UnitOfWork2 uow = new UnitOfWork2();
ActionProcedures.ClearTestRunDataCallBack del = (a,b)=>ActionProcedures.ClearTestRunData(a, b);
uow.AddCallBack(del, UnitOfWorkCallBackScheduleSlot.PreEntityDelete, true, new object[1] { _testRunID });

Here I define a lambda, and assign it to a variable which has as type the delegate to pass. Then I pass the delegate to the AddCallBack, et viola simple_smile

Equivalent without a lambda:

UnitOfWork2 uow = new UnitOfWork2();
uow.AddCallBack(new ActionProcedures.ClearTestRunDataCallBack(ActionProcedures.ClearTestRunData), UnitOfWorkCallBackScheduleSlot.PreEntityDelete, true, new object[1] {_testRunID});

Frans Bouma | Lead developer LLBLGen Pro