ado.net entity framework "retains" changes despite exiting transaction
hi guys I have some logic problem in my code (adonet entity framework)
here's the pseudocode
i = 0
while i < 5
using transactionreadcommited
{
var getuser = (from a in mydb.users where userid.equals(1) select a).firstordefault
try {
getuser.moneyBalance -= 10;
//error here
some command here causing expected error so it goes to catch ;
db.savechanges()
transaction.complete()
}catch{
i = i + 1
}
}
end while
the problem is,:
I get a new user in new transaction every time it retries in the while loop
User's initial money balance is 100.I minus 10, so it becomes 90
but if some command fails, it will exit the transaction and retry -
开发者_如何学编程in the 2nd loop, User's money becomes initial 90 - 10 = 80. shouldn't it revert back to 100, since I recreate a new transaction, and have not committed the first loop ?
精彩评论