How could I update only one field of my table by EF core? In another language how could I translate below SQL statement into EF Core :
UPDATE table_name SET column1 = value1 WHERE condition;
How could I update only one field of my table by EF core? In another language how could I translate below SQL statement into EF Core :
UPDATE table_name SET column1 = value1 WHERE condition;
I update it by below code
public async Task updateUserInfo(string token,long userId)
{
User user = _userRepository.GetDbContext().Set<User>().Find(userId);
user.token= token;
_userRepository.GetDbContext().Set<User>().Attach(user);
_userRepository.GetDbContext().Entry(user).Property(x => x.token).IsModified =true;
await _userRepository.GetDbContext().SaveChangesAsync();
}
I searched it on google and found a small example about this.
var stud = new Student(){ StudentId = 1, Name = "Bill" };
stud.Name = "Steve";
using (var context = new SchoolContext())
{
context.Update<Student>(stud);
context.SaveChanges();
}
I hope it will help your problem.