The Entity Context get the data from the database only once then it have cached in memory.
To get the data from the Database, you have first to call SaveChanges()
on Context1. Then, to call Refresh(RefreshMode.StoreWins, Context2.EntityToRefresh)
to get the database values in the context2.
You can also use a Share/Static context to do your queries, in that you can be sure that you have the same data for all your queries.
You can implement it like this
public class SharedObjectContext
{
private readonly WestwindEntities context;
#region Singleton Pattern
// Static members are lazily initialized.
// .NET guarantees thread safety for static initialization.
private static readonly SharedObjectContext instance = new SharedObjectContext();
// Make the constructor private to hide it.
// This class adheres to the singleton pattern.
private SharedObjectContext()
{
// Create the ObjectContext.
context = new WestwindEntities();
}
// Return the single instance of the ClientSessionManager type.
public static SharedObjectContext Instance
{
get
{
return instance;
}
}
#endregion
public WestwindEntities Context
{
get
{
return context;
}
}
}