Entity Framework does not update Foreign Key object

后端 未结 3 1176
南笙
南笙 2020-12-21 00:46

I\'m new to Entity Framework and this behavior confuses me:

    [Table(\"ClinicProfile\")]
    public class ClinicProfile
    {
        [Key]
        [Databa         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 01:27

    You just need to set ContactDataId, when updating

    clinicProfile.ContactData = contactData;
    clinicProfile.ContactDataId = contactData.Id;
    SharedContext.Current.Entry(clinicProfile).State = EntityState.Modified;
    SharedContext.Current.SaveChanges();
    

提交回复
热议问题