I am trying to do a simple update to the foreign key but the script never get sent over.
Here is the code I am using:
using (var db = new MyContext())
{
db.Entry<Contact>(newContact).State = EntityState.Modified;
newContact.ContactOwner = db.Person.Find(3);
db.SaveChanges();
}
EF6 update the rest of the column in the Persons table but it is not updating the Contact_Id in Persons table.
Person entity:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public List<Contact> ContactList { get; set; }
}
Contact entity:
public class Contact
{
public int Id { get; set; }
public string Email { get; set; }
public string TelNo { get; set; }
public Person ContactOwner { get; set; }
}
What am I missing here?
Please help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…