locked
Linq To sql- same value returned after an update RRS feed

  • Question

  • 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?

    Sunday, September 27, 2020 10:24 AM

All replies

  • https://social.msdn.microsoft.com/Forums/en-US/home?forum=linqtosql

    Link2SQL has a forum.

    Sunday, September 27, 2020 3:33 PM