EF怎么做关联实体更新?
有两个关联的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()