Add Function

Posts   
 
    
lgege
User
Posts: 27
Joined: 01-Sep-2005
# Posted on: 13-Oct-2005 21:40:35   

If table A to table B has one to many relation, when i create a new entity a as A and a new entity b as B, I can use a.B.Add(b) and adapter.save(a), which saves A and B at the same time. If A and B have one to one relation, I don't see any Add function as mentioned above. Is ther any other function that could acheive the same for tables with one to one realtion?

Thanks.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 14-Oct-2005 02:55:28   

lgege wrote:

If table A to table B has one to many relation, when i create a new entity a as A and a new entity b as B, I can use a.B.Add(b) and adapter.save(a), which saves A and B at the same time. If A and B have one to one relation, I don't see any Add function as mentioned above. Is ther any other function that could acheive the same for tables with one to one realtion?

Thanks.

Lgege,

Try

 a.B = b;
adapter.Save(a);

Thanks, Brian

lgege
User
Posts: 27
Joined: 01-Sep-2005
# Posted on: 14-Oct-2005 16:01:40   

Thanks. I will try that.

One more question on this one. If I do that, do I need to specifically set a.ForeignKey=b.Key or does this a.B=b takes care of this.

bclubb wrote:

lgege wrote:

If table A to table B has one to many relation, when i create a new entity a as A and a new entity b as B, I can use a.B.Add(b) and adapter.save(a), which saves A and B at the same time. If A and B have one to one relation, I don't see any Add function as mentioned above. Is ther any other function that could acheive the same for tables with one to one realtion?

Thanks.

Lgege,

Try

 a.B = b;
adapter.Save(a);

Thanks, Brian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-Oct-2005 16:57:59   

That's been taken care of: if b is new, the fk in a is synced after b is saved, otherwise it's synced right after the assignment. After the assignment, you also only have to save a (using a recursive save, default in adapter), and b is saved automatically as well, in the right order (so first b, then a). simple_smile

Frans Bouma | Lead developer LLBLGen Pro
lgege
User
Posts: 27
Joined: 01-Sep-2005
# Posted on: 18-Oct-2005 22:07:12   

Thanks for your help. It worked.