0

I use EF6 with DB-First. My DB contains 2 tables: Authors and Books. After load object with EF I delete row in DataBase directly (in SQL Manegment studio for example or use ExecuteNonQuery()), how to reload navigation property? I get to see the same records Books in myObj after Load(). If I insert directly into the database, the new records Books are visible after Load() on myObj.

var cnt = new Entities();
var myObj = cnt.Authors.
        Where(x => x.Name = "Author Name").
        Include("Books").
        FirstOrDefault();
// Delete directly in database (ex: Delete From Books Where ID = ...)
// DeleteDirect();
cnt.Entry(myObj).Collection("Books").Load();
egeo
  • 171
  • 1
  • 19

1 Answers1

0

Use the Refresh method of DataContext, to refresh the local copy of data:

DataContext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues,DataContext.Orders);
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171