subsonic 3 - 该操作对于事务状态无效
当我到达 ud.save() 时,我正在尝试以下代码,
UserDetail ud = UserDetail.SingleOrDefault(u => u.UserName == CurrentUserName);
if (ud == null)
ud = new UserDetail();
Address uAddress = ud.AddressId.HasValue
? Address.SingleOrNew(a => a.Id == ud.AddressId)
: new Address();
using (TransactionScope tc = new TransactionScope())
{
uAddress.Save();
ud.AddressId = uAddress.Id;
ud.Save(); // error is here
tc.Complete();
}
但收到错误“该操作对于事务状态无效”。 ---> System.Transactions.TransactionPromotionException:尝试促进事务时失败'
如果我注释掉事务部分它工作正常,不是 .SingleOrDefault 与数据库断开连接吗?
谢谢
I'm trying the following code
UserDetail ud = UserDetail.SingleOrDefault(u => u.UserName == CurrentUserName);
if (ud == null)
ud = new UserDetail();
Address uAddress = ud.AddressId.HasValue
? Address.SingleOrNew(a => a.Id == ud.AddressId)
: new Address();
using (TransactionScope tc = new TransactionScope())
{
uAddress.Save();
ud.AddressId = uAddress.Id;
ud.Save(); // error is here
tc.Complete();
}
when i reach ud.save() i get the error 'The operation is not valid for the state of the transaction. ---> System.Transactions.TransactionPromotionException: Failure while attempting to promote transaction'
if i comment out the transaction part it works fine, isn't .SingleOrDefault disconnecting from the db ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 TransactionScope 包装在 SharedDbConnectionScope 中,请参阅此处了解详细信息。 以下内容应该适用于您的示例
You need to wrap your TransactionScope in a SharedDbConnectionScope, see here for details. The following should work for your example
这是 subsonic 3.0.0.3 的一个错误,
可以在这里找到修复问题 69< /a>
it's a bug with subsonic 3.0.0.3
the fix can be found here issue 69