Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Bugs & Issues> Problem adding Hierarchical data
 

Pages: 1
Bugs & Issues
Problem adding Hierarchical data
Page:1/1 

  Print all messages in this thread  
Poster Message
lsberman
User



Location:

Joined on:
22-Feb-2006 02:03:45
Posted:
16 posts
# Posted on: 30-Mar-2007 21:31:44.  
Hi! I have two database tables Asset & Book. Book inherits from Asset in a 1:1 relationship. Unfortunately the following code fails with a FORIEGN KEY CONSTRAINT error (listed at bootom). Basically it's telling me that the Asset data needed to saved BEFORE the Book data. Neddless to say I thought the LLBL did this for me.

Anyway, I could use some advice as to how I should resolve this.

                BookEntity bookEntity = new BookEntity();

                //Data in the Asset Table
                bookEntity.Status = basicData.Status.ToString().ToUpper();
                bookEntity.Title = basicData.Title;
                bookEntity.SubTitle = basicData.SubTitle;
                bookEntity.Guid = Guid.NewGuid();

                //Data in the Book table
                bookEntity.PrimaryIsbn13 = basicData.PrimaryIsbn13;

                adapter.SaveEntity(bookEntity, true);

Error:

An exception was caught during the execution of an action query: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Book_Asset". The conflict occurred in database "Octavo", table "dbo.Asset", column 'Id'. The statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
  Top
bclubb
User



Location:
Norman, Oklahoma
Joined on:
12-Feb-2004 22:18:04
Posted:
934 posts
# Posted on: 31-Mar-2007 02:51:26.  
Here is my code that executes and doesn't give an error. I'll explain how I setup my Asset and Book Tables and maybe that will help us get on the same page in order to recreate this issue.

Code:

            using(DataAccessAdapter adapter = new DataAccessAdapter())
            {
                BookEntity bookEntity = new BookEntity();

                //Data in the Asset Table
                bookEntity.Name = "Applying Domain-Driven Design and Patterns";
                bookEntity.AssetId = Guid.NewGuid();

                //Data in the Book table
                bookEntity.Isbn = "0123456789";

                adapter.SaveEntity(bookEntity, true);
            }


[Asset]
AssetId (Guid, PK, No Default)
Name

[Book]
AssetId (Guid, PK, No Default)
ISBN

Relationship with Asset.AssetId PK and Book.AssetId FK



  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.