According to Entity Framework documents, Entity Framework will only cache data when using .Find()
to query data.
In the following sample I got query data cached when using .First()
:
static void Main(string[] args)
{
var trxScope = new TransactionScope();
var context = new SekhavatDBEntities();
//the value of Balance is Zero
var account =
context.Accounts.First(acc => acc.Id == new Guid("79B7AAC6-AD2D-4824-907E-16ADB4C41EE1"));
account.Balance = 50;
context.SaveChanges();
trxScope.Dispose();
var trxScope2 = new TransactionScope();
var account2 =
context.Accounts.First(acc => acc.Id == new Guid("79B7AAC6-AD2D-4824-907E-16ADB4C41EE1"));
//Balance of account2 Is 50 Now!
trxScope2.Dispose();
}
Why is account2's Balance 50? According to my considerations, it should be 0.
Thanks in advance