This is simple.When you modify state student2
entity framework thinks FirstName
and LastName
are null.
Instead using:
context.Entry(student2).State = EntityState.Modified;
You should change Property
:
context.Entry(student2).Property(x => x.Code).IsModified = true;