0

i take new Context object in main Window so Context object die only when i Close that window

     public Main_Window()
    {
        InitializeComponent();

    }
    DataContext DB = new DataContext();

my problem is after i created DataContextDB if i change the date in database from management studio not changing in DataContextDB to update the DataContextDB i must close the window and open it again

example 1 -create object

public partial class  Main_Window: Window
 {
   public Main_Window()
    {
        InitializeComponent();

    }
    DataContext DB = new DataContext();
 }

2- select using linq

var Q=from a in DB.Employee select new {a.Name};

result a.Name "AAAA"

3-change Employee name from management studio to "BBBB"

4- select using linq again

var Q=from a in DB.Employee select new {a.Name};

result a.Name Stile "AAAA" why when i changed the Employee name from management studio to "BBBB" not changed in object DataContext until to close window and open it again and i have other question when i Create Context object then i load all database in this object?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • The ef datacontext is not designed to be long-lived. It's much better to use as many datacontexts as required in a local scope, wrapped in a `using` statement. – spender Jun 01 '14 at 23:55
  • check this http://stackoverflow.com/questions/2098143/how-to-clear-the-datacontext-cache-on-linq-to-sql –  Jun 02 '14 at 00:06

0 Answers0