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!
Persons
class ? – PolytonalitynewPerson.Contact
doesn't match withpublic Person ContactOwner { get; set; }
? and DoesnewPerson
a new entity or a modified entity ? – PolytonalitynewContact.Person
andpublic Person ContactOwner { get; set; }
, DoesnewContact
has existing reference to anyPerson
? – Polytonality