Hi there,
I have a many to many table structure as follows:
Contact -> ContactCode -> FundraiserCode
I bind a grid of codes to the current contact by setting the datasource of my grid to
Contact.FundraiserCodeCollectionViaContactCode
When new Codes are added to the current contact I simply
Contact.FundraiserCodeCollectionViaContactCode.Add(code);
and it works beautifully, but only when I'm working with a contact that already exists in the database.
When creating a new contact, and assigning new codes via
FundraiserCodeCollectionViaContactCode.Add(code), the code is added to the collection, and the grid updated. However, when I save the entity I get the following exception.
An exception was caught during the execution of an action query: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ContactCode_Contact". The conflict occurred in database "ct10012", table "dbo.Contact", column 'ContactID'.
The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
It looks to me as if the ContactCode entity is being saved before Contact.
Doesn't LLBLGen have code that knows in what order to save entities to the database? Or am I going about this wrong?
Thanks,
Josh