EF Code First Detached Entity not updating object reference
Posted
by
Alvaro
on Stack Overflow
See other posts from Stack Overflow
or by Alvaro
Published on 2012-11-13T17:14:21Z
Indexed on
2012/11/14
23:00 UTC
Read the original article
Hit count: 341
I'm posting the exact entity:
public class Person : ContactableEntity
{
public Plan Plan { get; set; }
public int Record { get; set; }
public int PersonTypeValue { get; set; }
}
I'm using the following code to update in a disconected context fashion:
public void Update(DbSet MySet, object Obj)
{
MySet.Attach(Obj);
var Entry = this.Entry(Obj);
Entry.State = EntityState.Modified;
this.SaveChanges();
}
This is a method exposed by my dbContext Called this way:
PersistentManager.Update(PersistentManager.Personas,UpdatedPersona);
The problem is, EF will update any property but the referenced Plan object. Can someone tell me where is the mistake? In advance : the entity reaches the point of update with all the properties correctly set. EF just fails to update the FK in the Database (no exception though)
© Stack Overflow or respective owner