ado.net实体框架“保留”尽管退出交易仍会发生变化
大家好,我的代码(adonet 实体框架)中有一些逻辑问题,
这是伪代码,
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
问题是:
每次在 while 循环中重试时,我都会在新交易中得到一个新用户 用户
的初始资金余额是 100.I 减去 10,所以它变成 90,
但如果某个命令失败,它将退出交易并重试 -
在第二个循环中,用户的钱变成初始 90 - 10 = 80。它不应该恢复到 100,因为我重新创建了一个新交易,并且还没有提交第一个循环?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论