How to update only one field using Entity Framework?

前端 未结 16 1854
后悔当初
后悔当初 2020-11-22 09:09

Here\'s the table

Users

UserId
UserName
Password
EmailAddress

and the code..



        
16条回答
  •  无人共我
    2020-11-22 09:40

    In Entity Framework Core, Attach returns the entry, so all you need is:

    var user = new User { Id = userId, Password = password };
    db.Users.Attach(user).Property(x => x.Password).IsModified = true;
    db.SaveChanges();
    

提交回复
热议问题