I want to update few columns on my table.
public void LogOutUser(int systemUserId)
{
DatabaseContext context = new DatabaseContext ();
var user = new SystemUser()
{
SystemUserId = systemUserId,
IsLocked = true,
IsLoggedIn = false
};
context.SystemUsers.Attach(user);
context.Entry(user).Property(x => x.IsLocked ).IsModified = true;
/context.Entry(user).Property(x => x.IsLoggedIn ).IsModified = true;
context.SaveChanges();
}
It's giving me an error "Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.". I am aware that this error happens because I have some Properties in my "SystemUsers" class that are required, like Email, FullName, etc. I could have easily done it when I use connected scenario..
var user = context.SystemUsers.Find(systemUserId);
user.IsLocked = true;
user.IsLoggedIn = false;
context.SaveChanges();
But I don't want to use this way as I believe it's a waste of resources as I have to fetch the whole row first then update it. Now, my question is, what is the best way to update EF using disconnected scenario given that I only have "systemUserId" as a way of telling the EF that this data is existing in my database.