Linq To sql- same value returned after an update

  • Thread starter Thread starter want 2 Learn
  • Start date Start date
W

want 2 Learn

Guest
i am doing the next :

DataContext1 context = new DataContext1();
//before
DataContext ctx1 = new DataContext();
Account account = ctx1.Accounts.FirstOrDefault(t => t.AccountID == AccountID);
decimal? accountBalance = account.Balance == null ? 0 : account.Balance;
context.UpdateLog(tranID, "Added1:accountID:" + AccountID + ",balance before:"+ accountBalance, responseCode);
context.updateAccountBalance(AccountID, Price);
//after
DataContext ctx2 = new DataContext();
account = ctx2.Accounts.FirstOrDefault(t => t.AccountID == AccountID);
accountBalance = account.Balance == null ? 0 : account.Balance;
context.UpdateLog(tranID, "Added2:accountID:" + AccountID + ",balance after:" + accountBalance, responseCode);


what happend is i write to log :

Added1:accountID:333,balance before:124

Added1:accountID:333,balance after:124

this happens when i don't use a second Data Context:

DataContext ctx2 = new DataContext();

in the

updateAccountBalance

stored procedure i am updating using the begin trans....commit.

when i the

ctx2

and check the value then the log is correct :

Added1:accountID:333,balance before:125

Added1:accountID:333,balance after:128

why is this happens? session issue?

Continue reading...
 
Back
Top