Код: Выделить всё
MyContext context = new MyContext();
Person myPerson = context.PersonSet.FirstOrDefault();
String myPersonName = myPerson.Name;
Address myPersonAddress = myPerson.Address;
Код: Выделить всё
context.Entry(myPerson).Reload();
Как я могу принудительно перезагрузить ассоциацию адреса (и все другие ассоциации в классе Person)?
РЕДАКТИРОВАТЬ:
В одном и том же случае у человека может быть более одного адреса.
Код: Выделить всё
MyContext context = new MyContext();
Person myPerson = context.PersonSet.FirstOrDefault();
String myPersonName = myPerson.Name;
List myPersonAddresses = myPerson.Addresses;
Код: Выделить всё
context.Entry(myPerson).Reference(p => p.Address).Load();
// Address will be populated with only the new address
// this isn't required because I use lazy loading
Код: Выделить всё
context.Entry(myPerson).Collection(p => p.Addresses).Load();
// Address will be populated with old value and new value
Код: Выделить всё
context.Entry(myPerson).Collection(p => p.Addresses).CurrentValue.Clear();
context.Entry(myPerson).Collection(p => p.Addresses).Load();
Подробнее здесь: https://stackoverflow.com/questions/908 ... -framework
Мобильная версия