I have done something similar within my application. Try something Like I have below (I usually use a repository for this so change to suit your needs);
private void UpdatePerson(PersonViewModel v)
{
using (ProActiveDBEntities context = new ProActiveDBEntities())
{
var p = context.Users.Where(c => c.PersonID == v.PersonID).SingleOrDefault(); //retrieve the person by its PK ID
if (p != null)
{
p.PersonID = v.PersonID; //Map the properties/Fields within your EF model to the ones in your view model
p.Surname = v.Surname;
//etc...
context.SaveChanges();
}
}
}
Like I said, I usually use a repository to create my CRUD operations for EF. But within the method, I have a parameter of my ViewModel. I then create an expression that matches the ID of the entity table to the ID of the ViewModel. It then updates the corresponding data in which is mapped.
Then, within my ViewModel I do the following - for example;
private Void Update()
{
PersonRepository rep = new PersonRepository();
rep.UpdatePerson(this);
}
This is my way of achieving this. There are different ways and different approaches that you can do.
If I have missed something then let me know :). Hope this helped! :)