D
Dick
I get the exception: “An entity object cannot be referenced by multiple
instances of IEntityChangeTracker†when I attempt to attach my object to my
context.
Here's my code
public Customer Fetch(int ID)
{
using (OIC2Entities context = new OIC2Entities())
{
Customer Customer = (from c in context.Customer where
c.ID.Equals(ID) select c).First();
Customer.Project.Load();
return Customer;
}
}
public void Save(Customer Customer)
{
using (OIC2Entities context = new OIC2Entities())
{
context.Attach(Customer);
ObjectStateEntry objectStateEntry =
context.ObjectStateManager.GetObjectStateEntry(Customer.EntityKey);
foreach (FieldMetadata fieldMetadata in
objectStateEntry.CurrentValues.DataRecordInfo.FieldMetadata)
{
objectStateEntry.SetModifiedProperty(fieldMetadata.FieldType.Name);
}
context.SaveChanges();
}
}
instances of IEntityChangeTracker†when I attempt to attach my object to my
context.
Here's my code
public Customer Fetch(int ID)
{
using (OIC2Entities context = new OIC2Entities())
{
Customer Customer = (from c in context.Customer where
c.ID.Equals(ID) select c).First();
Customer.Project.Load();
return Customer;
}
}
public void Save(Customer Customer)
{
using (OIC2Entities context = new OIC2Entities())
{
context.Attach(Customer);
ObjectStateEntry objectStateEntry =
context.ObjectStateManager.GetObjectStateEntry(Customer.EntityKey);
foreach (FieldMetadata fieldMetadata in
objectStateEntry.CurrentValues.DataRecordInfo.FieldMetadata)
{
objectStateEntry.SetModifiedProperty(fieldMetadata.FieldType.Name);
}
context.SaveChanges();
}
}