This is a migrated thread and some comments may be shown as answers.

Problems saving child object

1 Answer 58 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Casper
Top achievements
Rank 1
Casper asked on 13 May 2009, 09:34 PM
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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Zoran
Telerik team
answered on 14 May 2009, 11:55 AM
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.
Tags
Development (API, general questions)
Asked by
Casper
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or