Hello,
i'm working with Entity Framework only few weeks. It's great, but how should i add corectly new row with referenced sub-items (tables)?
i tried this procedure
CMS.ShopOrder order = new CMS.ShopOrder();
order.CreatedOn = DateTime.Now;
foreach (var item in CMS.CurrentSession.Cart.Items)
{
order.ShopOrderItems.Add(item);
}
db.AddToShopOrder(order);
int selT = FormatHelper.GetInt32(ddTransport.SelectedValue);
int selP = FormatHelper.GetInt32(ddTransport.SelectedValue);
order.Transportation = db.Transportation.Where(t => t.Id == selT).FirstOrDefault();
order.Payment = db.Payment.Where(p => p.Id == selP).FirstOrDefault();
order.Customer = db.Customer.Where(c=>c.Id == CMS.CurrentSession.Customer.Id).FirstOrDefault();
db.SaveChanges();
but i got error:
An entity object cannot be referenced by multiple instances of IEntityChangeTracker. Line 492: base.AddObject("ShopOrder", shopOrder);
Can i add all this records at once?
Thanks a lot.