UnitOfWork2 with IDENTITY

Posts   
 
    
mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 15-May-2008 20:37:12   

Hi,

I have 2 tables user , userdetail user table has userID that is IDENTITY is true

and userdetail has userID referance to user table

how to acheive inserting in user and userdetail with UnitOfWork2

LLBL 2.5 v with Adapter

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 16-May-2008 10:00:54   

Please check the first code example in the manual's section "Using the generated code -> Adapter/SelfServicing -> Unit of work and field data versioning"

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 19-May-2008 17:41:18   

Hi walaa,

i read it but still finding problem to use this column with IDENTITY it's return 0


                uow.AddForSave(toSave,true);
                uow.AddForSave(SaveWithdrawalVoucher(toSave.UserID);
                uow.Commit(DataAccess.DataAdapterFactory.Create(), true);

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 19-May-2008 20:45:19   

are you getting an exception?

mohamed avatar
mohamed
User
Posts: 136
Joined: 10-Mar-2008
# Posted on: 20-May-2008 11:54:19   

No ther is no exception

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 21-May-2008 08:39:09   
            uow.AddForSave(toSave,true);
            **uow.AddForSave(SaveWithdrawalVoucher(toSave.UserID)**;
            uow.Commit(DataAccess.DataAdapterFactory.Create(), true);

Please post real compilable code.

i read it but still finding problem to use this column with IDENTITY it's return 0

Also please post your code to test for the identity value.

From the manual's example: you should only add the main entity, with setting the recurse parameter to true, and then the related entities would be added too.

eg.:

CustomerEntity newCustomer = new CustomerEntity();
// ... fill newCustomer's data
AddressEntity newAddress = new AddressEntity();
// ... fill newAddress's data
newCustomer.VisitingAddress = newAddress;
newCustomer.BillingAddress = newAddress;
UnitOfWork2 uow = new UnitOfWork2();
// add the customer for a recursive save action and specify true 
// so the entity is refetched after the save action.
uow.AddForSave(newCustomer, true);

DataAccessAdapter adapter = new DataAccessAdapter();
// commit all actions in one go
uow.Commit(adapter, true);
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 21-May-2008 11:28:35   

Walaa.. I have worked with Mohammad on this problem and this is what happened. The UOW was not even saving the entity and this error took us a whole day to debug with no luck. Eventually what Mohammad did was as follows: He closed VS, deleted OBJ/BIN folders from the WEB and BL projects. The after re-opening the VS solution and rebuilding, MAGICALLY the UOW is saving the entities successfully.

What I would like to ask you is the following: 1- Each time we generate new DAL dlls, we copy them to the LIB folder referenced by the projects. All this is done while the WEB/BL solution is open. We do a solution clean from inside VS and rebuild.

Would you recommend a better approach?

2- When using a UOW to save entity with an identity property as the following senario: uow.AddForSave(a, true) //a has an identity property //.... uow.AddForSave(b) //b has a property that requires the identity value from entity a uow.Commit(adapter,true)

will I be able to know the new identity value of entity a after adding it to uow or only after I commit uow?

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 21-May-2008 12:58:16   

will I be able to know the new identity value of entity a after adding it to uow or only after I commit uow?

Since the identity is set by the dbms, seems to me you would have to commit. Is that diffrent than what you are seeing?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 21-May-2008 16:53:49   

1- Each time we generate new DAL dlls, we copy them to the LIB folder referenced by the projects. All this is done while the WEB/BL solution is open. We do a solution clean from inside VS and rebuild.

Would you recommend a better approach?

Copy and paste are fine, but you need to know that web applications tend to keep referencing old libraries from temporary location, unless the application is restarted. So I guess you need to restart the web application to make sure it uses the new dlls.

2- When using a UOW to save entity with an identity property as the following senario: uow.AddForSave(a, true) //a has an identity property //.... uow.AddForSave(b) //b has a property that requires the identity value from entity a uow.Commit(adapter,true)

will I be able to know the new identity value of entity a after adding it to uow or only after I commit uow?

UoW only saves when Commit is called. So you have to follow the example I copied from the manual, if you want to save related entities and make use of the recursive save option.