Saving EntityCollection with related tables to a database

Posts   
 
    
prabhu
User
Posts: 77
Joined: 20-Dec-2006
# Posted on: 25-Mar-2008 16:33:22   

Hi,

I am using LLBLGenPro 2.5 runtime Version and Adapter model.

My scenario is user will upload a Excel file that contains list of values for related tables in a single row..

Say for example i am having follwoing tables

Person,PersonLocation,PersonSpecialty,PersonDepartment

Relationship is:

A person(Person) can work in more than one location(PersonLocation)

PersonSpecialty can have one or more personlocation id's.

Basically i am getting all the rows from the excel file in a custom collection. I need to use SaveEntityCollection method of adapter while inserting the record against the db.

Suppose in the above case if i am going to insert some new data into person table, whether i can able to get the id(primary key here) of newly inserted row so that i can use the same for inserting new data into the personlocation table.

Please guide me by providing some samples or leads.

Help is very much appreciated.

Regards

Prabhu

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 25-Mar-2008 20:18:20   

How are you creating this custom collection ?

prabhu
User
Posts: 77
Joined: 20-Dec-2006
# Posted on: 26-Mar-2008 02:14:07   

The custom collection contains the list of values for all the related tables. I need to log the status(both success and exception) of each and every row after insertion or updation.

My idea is iterate custom collection and populate all the related tables. If the primary key of an related entity is not there i want to insert else update.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Mar-2008 11:11:36   

This can easily be done be LLBLGen Pro using a recursive save, as the PK-FK values will be synced automatically for you.

Please check Saving entities recursively in the LLBLGen Pro manual's section: "Using the generated code -> SelfServicing/Adapter -> Using the entity classes"