EF Update using EntityState.Modified

前端 未结 3 1963
一个人的身影
一个人的身影 2021-02-08 05:40

Usually I\'m using this code

Member member = ctx.Members.Find(id);
member.Name = txtName.Text;
ctx.Entry(member).State = EntityState.Modified;
ctx.SaveChanges();         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-08 06:13

    Like the other guys have mentioned your context tracks the changes to the object automatically.

    I find it more useful for instance when I use return json to a mvc controller where the original object loses change tracking when first converted to json for the view. In that case I have to specifically set the objects entity state before saving changes.

提交回复
热议问题