Using Related Entities

Posts   
 
    
Emmanuel
User
Posts: 167
Joined: 13-Jan-2006
# Posted on: 29-Mar-2006 16:55:26   

I am writing my first app using llblgen. I have run into an issue with llblgen that is confusing me. It involves the proper sequencing of recursive saves so that PK-FK constraints are observed.

I have an m:1 relationship between table Bids and table Member (for every bid in Bids there is 1 and only 1 bidder from the Members table). And Bids has a 1:n relationship to Auctions.

I am writing code that creates an Auction entity and then Add()s Bids to its Bids property. For each Bid I am checking whether the bidder exists already. If not, I am also setting field values for the Bid's Members property to the new desired values (including setting the PK - Bids.Members.MemberId).

Then I save the whole thing recursively using Save(true). I am using self-servicing.

An exception is thrown because of a violation of the FK_Bids_Members constraint. This surprises me because I though llblgen would take care of persisting the bidder into the Members table before the Bid. I tried setting Bids.Members.IsNew to 'true' thinking that maybe I need to do this to ensure that it gets flagged to be persisted but that doesn't help (besides I think I saw that this flag was already set to 'true' during debugging.

I got around the problem by creating a standalone Member entity and saving it before going on to saving the Auction entity (and the auction's Bids by sepcifying recursive save using a 'true' param in Save()).

This doesn't seem right to me. Surely llblgen should be handling this for me. I must be setting something up incorrectly.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 29-Mar-2006 17:01:07   

Please post some code which sets up the graph before saving. Also, be sure you're using runtimes which are released on March 17th, as those contain a new recursive save queue sorting implementation (the graph sorting algo which was implemented could fail in some situations).

Frans Bouma | Lead developer LLBLGen Pro