有两个关联的EF实体,关系如下:
public class Member
{
public int Id { get; set; }
public string Fullname{ get; set; }
public string Nickname { get;set; }
public Detail Detail{ get;set;}
}
public class Detail
{
public int DetailId { get; set; }
public string Address{ get; set; }
public Member Member { get; set; }
}
我的数据更新代码是这样写的:
Member entity = Context.Member.FirstOrDefault(p=>p.Id == id);
entity.Fullname = "菜鸟";
entity.Detail.Address = "xx";
Context.Member.ApplyCurrentValues(entity);
Context.SaveChanges()
可是为什么代码执行后 Member.Fullname的数据更新了,但Detail.Address的数据没有更新?
------解决方案--------------------
在映射关系中找Cascade。
加在Member端