PK Clone question

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 27-Jun-2007 15:49:26   

I have a Sale object that has a PK 'SaleID'. It is not auto numbered, but is the PK in the designer. (NOT read-only in designer).

The Sale has a child object SaleInfo linked on SaleInfo.SaleID = Sale.SaleID. SaleInfo has a child MoreSaleInfo linked on both SaleID AND SaleInfoID PKs.

I clone the Sale object with a BinarySerializer and get all the children fine.

Now, I need to change the SaleID PK on the top level SaleID then save it back to the DB as a new Sale.

Question: When I change the Sale.SaleID , will the SaleInfo.SaleID and MoreSaleInfo.SaleID get updated too?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Jun-2007 15:52:48   

I think it should, with a recursive Save.

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 27-Jun-2007 15:57:10   

So the rule would be:

Any child object that is joined to a parent object via field(s) that are marked as "Is PK" in the designer will have its FK value updated when the parent PK is updated.

Assuming: In the Designer, the PK field is not "Read-only" and is not "Is Identity / Sequence" checked.

Ian

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Jun-2007 16:23:53   

So the rule would be:

Any child object that is joined to a parent object via field(s) that are marked as "Is PK" in the designer will have its FK value updated when the parent PK is updated.

It's not that simple, it depends on the version of LLBLGen Pro used, and on whether the Original entity is new or it was fetched from the database, so re-setting the PK might de-reference the related entities.

Maybe you want to have a look at the following threads: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9636 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9620 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=6860 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=6241

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 27-Jun-2007 16:50:54   

If I started from the bottom of the entity tree and change the FKs to the new one and move up, would that always work?

I use 2.0, Self-servicing, newest Designer .

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Jun-2007 17:28:18   

If I started from the bottom of the entity tree and change the FKs to the new one and move up, would that always work?

Your previous solution should work, in case of a new root entity. And for updates, you can just update the PK of the main entity, and then starting adding entities to it to re-build the tree. Or you might go to a database solution, which is setting Cascading Updates to true.