I want update family of a person who his name is pejman. This is my object Class:
public class Person
{
public int Id { get; set; }
public string FirstNa
You are missing an Id field when creating an instance of Person object. Because of this Entity Framework is not able to find an existing Person.
Your code should look like this:
public static void Update(int id, string name, string family)
{
var _person = new Person() { Id = id , FirstName = name, LastName = family };
using (var newContext = new MyDbContext())
{
newContext.Persons.Attach(_person);
newContext.Entry(_person).Property(X => X.LastName).IsModified = true;
newContext.SaveChanges();
}