Accessinge entities from UnitofWork for extra update

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 30-Aug-2007 10:58:16   

Hi,

I have a table with Projects. In this table Projects can be related to eachother. For example: An Internal project can be related to multiple external project. This information is stored on the external project and it uses a column InternalProjectID for this. This column is NULL of course for an internal project.

I now have a function in the business layer. This function has as parameters a UnitOfWork and an array.

The UnitOfWork contains a new project that has to be inserted/updated. It's a unitofwork because a lot of extra data also related to the project is inserted at the same time.

The problem lies with new projects. These new projects do not have a projectID, it's autoidentity and retrieved after the insert/update from the unitofwork using the refetch parameter. But in the business layer I already need this new projectID to update all the projects of which the projectID is on the array, setting the InternalProjectID to this new id. And this all must be done in the same transaction.

Code I have so far:


DataAccessAdapter adapter = new DataAccessAdapter();

adapter.StartTransaction(IsolationLevel.ReadCommitted, "ProjectSave");

// then some delete stuff first

uow.Commit(adapter);

//In here I need to insert/update the other projects

adapter.Commit();


There's only one ProjectEntity in the uow and uses recursive to save all the other related data, so only this line is used:

uow.AddForSave(currentProject, null, true, true);

Can someone tell me how I can retrieve the project id between the uow.Commit and the insert/update of the other projects?

Thank you very much,

  • G.I.
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Aug-2007 11:50:02   

uow.AddForSave(currentProject, null, true, true);

How do you fill in the currentProject?

This should be the InternalProject, which should have a collection of related externalProjects, and if you fill the externalProjects collection property of the currentProject, and you specify a recursive save (as you did), the PK-FK will be automatically synched for you.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 05-Sep-2007 23:25:30   

Just as a reply, since I think I should at least answer my own threads: Thank you, I was thinking stupid ... smile