Add New Entity in Collection of another new Entity

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 06-Sep-2005 10:01:38   

Hi,

I have a new projectEntity which I store in the session of my webapplication. It is not saved to the database until the user specifically clicks the Save button.

A Project can have several Tasks. So I have a Properties on ProjectEntity called Tasks which is a collection of TaskEntities.

Now I would like a to add a new child task entity to my new project entity, but since I don't have a value for the PK of a project (I don't get this until I save it to the database) and my Task collection is not specified, I don't know how to do this.

I am using Self Servicing...

Please help me, thanks in advance,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Sep-2005 10:42:38   

Just add the child task to the Tasks collection of the project entity and when saving project, you call myproject.Save(true), which is a recursive save. It will then automatically set the FK in all the tasks, after project is saved, so you don't have to worry about PK values of the project entity.

Frans Bouma | Lead developer LLBLGen Pro