In my ViewModel, I have code like this:
public class OrderViewModel
{
private UserOrder order;
private DeliveryCentre deliveryCentre;
private CatalogueContainer catalogue = new CatalogueContainer();
public void Save()
{
if (order == null)
{
order = catalogue.UserOrders.CreateObject();
}
if ((deliveryCentre == null)
|| (deliveryCentre.Id != deliveryCentreId))
{
deliveryCentre = catalogue.DeliveryCentres.First(centre => centre.Id == deliveryCentreId);
order.DeliveryCentre= deliveryCentre;
}
catalogue.SaveChanges();
}
So, when the delivery center is new and the new order, I got into the old "The relationship between two objects cannot be determined because they are tied to different ObjectContext objects", which seems to me a little unfair - I just can not understand what I need done to make them more similar to the same object context. I assume this is due to some fundamental misunderstanding of the behavior of the Entity Framework.
source
share