Entity Framework, one-to-many, several columns -
if have main table, lets orders, , sub table of items , items table has fields item number has nullable (optional) field color applied items. how update items table, @ same time orders table, using entity framework?
here code example of have far. 2 problems, i'm entering 1 of items and, research indicates, can't add field items table?
foreach (guid c in allitems) { items.orderitemid = guid.newguid(); itemsorderid = order.orderid; items.itemid = c; if (itemid = itemthatletsyouchoseacolorid) { items.itemcolorid = colorid; } else { items.itemcolorid = null; } } context.orders.addobject(orders); context.items.addobject(items); context.savechanges();
my orders table gets record inserted, , items gets 1 record inserted. i'm missing basic here, i'm afraid. btw, entity framework 4.0, which. believe, not require use of entitykey.
you're adding object items
collection 1 time after scope of foreach
.
have tested like:
foreach (guid c in allitems) { var item = new item(); item.orderitemid = guid.newguid(); item.orderid = order.orderid; item.itemid = c; if (itemid = itemthatletsyouchoseacolorid) { item.itemcolorid = colorid; } else { item.itemcolorid = null; } context.items.addobject(items); } context.orders.addobject(order); context.savechanges();
and i'm not sure understand mean
i can't add field items table
you should more precise expect. insert row, add column in table...? "field"?
Comments
Post a Comment