UnitOfWork and Stored Procedures

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 27-Oct-2005 13:56:09   

Hi,

Since I want some cleaner code I wanted to add stored procedures to a unit of work and execute them that way. The only problem is, that SP A returns a value via output parameter, which I have to insert in SP B. Is this possible using a unit of work, or should I just call the stored procedure using the adapter in the normal way?

Gr.,

Robin

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Oct-2005 02:47:34   

I don't believe it's possible. I think you would be better off doing to the normal way using the adapter.

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 29-Oct-2005 00:18:49   

You could use the UnitOfWork callback feature to call a method during the uow Commit which then fires the stored procedure...

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 31-Oct-2005 08:51:49   

Marcus,

that sounds exactly what I want, but I don't really know how I should set this up then? Can you maybe help me on the way?

Tia,

G.I.

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 31-Oct-2005 10:56:09   

G.I. wrote:

Marcus,

that sounds exactly what I want, but I don't really know how I should set this up then? Can you maybe help me on the way?

Tia,

G.I.

Check the Documentation in Generated code - Unit of work and field data versioning, Adapter - UnitOfWork usage: stored procedures for a detailed example. simple_smile

// C#
UnitOfWork2 uow = new UnitOfWork2();
uow.AddCallBack(new ActionProcedures.ClearTestRunDataCallBack(ActionProcedures.ClearTestRunData), 
    UnitOfWorkCallBackScheduleSlot.PreEntityDelete, true, _testRunID);
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 31-Oct-2005 13:46:24   

Marcus,

I know how to add sp's to the uow with callback, but what I meant is:

If I define a UnitOfWork and add sp A with a Callback, this would get executed and I would get the output parameter ParamA1 back. I then have to pass ParamA1 to spB.

So in Code, I would declare a unitOfWork, declare ParamA1 parameter, add the sp A with ParamA1 to the unitOfWork, add sp B with ParamA1 to this unitOfWork and then call UnitOfWork.Commit();

How would that make sure that by sp B uses the value that sp A returns

Gr.,

G.I.

Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 31-Oct-2005 14:54:37   

G.I. wrote:

Marcus,

I know how to add sp's to the uow with callback, but what I meant is:

If I define a UnitOfWork and add sp A with a Callback, this would get executed and I would get the output parameter ParamA1 back. I then have to pass ParamA1 to spB.

So in Code, I would declare a unitOfWork, declare ParamA1 parameter, add the sp A with ParamA1 to the unitOfWork, add sp B with ParamA1 to this unitOfWork and then call UnitOfWork.Commit();

How would that make sure that by sp B uses the value that sp A returns

Gr.,

G.I.

OK... rather than using the default Delegates which are generated by LLBLGen i.e. the delegate returned by ActionProcedures.ClearTestRunDataCallBack(ActionProcedures.ClearTestRunData)... you simply supply a delegate to one of your own methods which in turn calls the stored proc and then stores the return value in thread safe storage. The next SP calls back into your second method which retrieves the value from thread safe storage and calls the second proc... etc

This is a bit of a messy way to acomplish the task. I haven't thought it through very well, so there might well be an easier way...