Problems saving child object

2 posts, 1 answers
  1. Casper
    Casper avatar
    4 posts
    Member since:
    Feb 2009

    Posted 13 May 2009 Link to this post

    Hi,

    I'm trying to build a kind of shop where I want to save my basket in the db.

    I'm using the 'Best Practices in web development with OpenAccess' sample Link

    My db setup is 2 tables. Basket and BasketItems where BasketItems have a FK to Basket

    When i'm trying to commit the objects i gives me this error: #23000Column 'BasketID' cannot be null 
    Line 117:     case TransactionProvider.OpenAccess:
    Line 118:     {
    Line 119:         scope.Transaction.Commit();
    Line 120: break; Line 121: }

    My code:
    Basket basket = new Basket();    
    basket.Basketid = '2a3edc4a-3108-430a-ac2a-5e027cf1d090';   
    basket.Customerid = 'dde49816-0223-4678-8ecd-e0f49f9610f0';     
        
    BasketItem item = new BasketItem();     
    item.Price = 12.5;     
    item.Size = 5;     
    item.Color = 'Blue'    
    item.Quantity = 2;     
        
    basket.Items.Add(item);     
        
    objectScope.Add(basket); 

    What am i doing wrong?
  2. Answer
    Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 14 May 2009 Link to this post

    Hello Casper,

    You have the one-to-many list managed e.g. when you add an object to the list it sets the foreign key field as appropriate, you should set the collection to "managed". That you can achieve by opening the forward-mapping wizard clicking on the Items field in the treeview on the left and than check the Manage Collection checkbox.

    This should solve the problem but if you require any other suggestions/clarifications we are here to help.

    Best wishes,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
Back to Top