Entity saving order

Posts   
 
    
dganesh
User
Posts: 10
Joined: 17-Nov-2011
# Posted on: 24-Feb-2012 19:02:54   

Hi there, Product: LLbLGen Pro v3.1 Final Runtime Library: 3.1.11.907 Database: SQL Server 2008/ Oracle 11i We use .NET 4.0 framework and VB.Net

We are trying to save the entity to the database using the following code:

adapter.SaveEntity(employeeEntity, False, True)

We have a number of child entities associated with the "employeeEntity". When we save the entity, we want to save the parent entity first and then the child entities.

But now as per the above line of code, the child entities are saved first and then the parent entity.

Is there some setting or property that we need to set to define the order in which the parent and child entities should be saved?

Thanks for your help, Dharini

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Feb-2012 20:36:06   

Hi Dharini,

LLBLGen does this for a reason. Usually because of the dependencies between the entities. It's likely your employee entity depends on those child entities (FKs).

Inside a recursive save you can't decide the order of the saves. What you can do is save them in your custom order and enclose them in a transaction:

adapter.StartTransaction(...);

adapter.SaveEntity(employeeEntity.Some, false, fasle);
adapter.SaveEntity(employeeEntity.SomeOther, false, fasle);
adapter.SaveEntity(employeeEntity.SomethingElseEntity, false, fasle);
adapter.SaveEntity(employeeEntity, false, fasle);

adapter.Commit();
David Elizondo | LLBLGen Support Team