0

like this:

var Person = context.Persons.Find(10);
Persons UpdatedPerson = new Persons ({...});
Person = UpdatedPerson;
context.SaveChanges();

But the Context is 'unchanged'?

1 Answers1

0
var Person = context.Persons.Find(10);
Persons UpdatedPerson = new Persons ({...});
context.Entry(Person).CurrentValues.SetValues(UpdatedPerson);
context.SaveChanges();

UpdatedPerson must have the same key value (10) as Person. This will update all scalar and complex properties of Person but not entities related by navigation properties of Person.

Slauma
  • 175,098
  • 59
  • 401
  • 420
  • Thats the way - thx. But how can I update the whole related properties? – user2273950 May 13 '13 at 09:33
  • @user2273950: You must load the related entities and then update them one-by-one. An example for a child collection is here: http://stackoverflow.com/questions/5538974/the-relationship-could-not-be-changed-because-one-or-more-of-the-foreign-key-pro/5540956#5540956 – Slauma May 13 '13 at 09:46