Exclude Property on Update in Entity Framework

后端 未结 5 1139
野性不改
野性不改 2020-11-28 04:53

I\'ve been looking for a proper way to mark a property to NOT be changed when updating a model in MVC.

For example, let\'s take this small model:

cla         


        
5条回答
  •  感动是毒
    2020-11-28 05:28

    Anyone looking for how to achieve this on EF Core. It's basically the same but your IsModified needs to be after you add the model to be updated.

    db.Update(model);
    db.Entry(model).Property(x => x.Token).IsModified = false;
    db.SaveChanges();
    

提交回复
热议问题