Is there any method to update an object from a strongly typed object without listing each field ?
Lets consider the following case:
using (var context = new MyDBEntities())
{
var user = (User)Session["EditedUser"];
var oldUser = context.Users.FirstOrDefault(o => o.Id == user.Id);
oldUser.FirstName= user.FirstName;
oldUser.LastName = user.LastName;
etc ....
context.SaveChanges();
}
I have 29 more fields and I am not willing to write them down one by one every time. What I am looking for should be similar to this
using (var context = new MyDBEntities())
{
var user = (User)Session["EditedUser"];
var oldUser = context.Users.FirstOrDefault(o => o.Id == user.Id);
oldUser=user;
context.SaveChanges();
}
Which fails for sure because of the entity's primary key violation. What I would like to achieve here is to update all the fields except the primary key value.