首页 新闻 赞助 找找看

EF 异常The Transaction property of the command has not been initialized.

0
悬赏园豆:160 [待解决问题]

异常信息如下:

System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.InvalidOperationException: ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.

EF
chester·chen的主页 chester·chen | 小虾三级 | 园豆:507
提问于:2018-12-20 15:49
< >
分享
所有回答(2)
0

事务尚未初始化

徒然喜欢你 | 园豆:1741 (小虾三级) | 2018-12-20 16:50

没有用事务,只是一个查询

_sendNotificationRepository.GetMany(m => id2 == m.Id)

支持(0) 反对(0) chester·chen | 园豆:507 (小虾三级) | 2018-12-20 16:51

@老六代码: try catch一下

支持(0) 反对(0) 徒然喜欢你 | 园豆:1741 (小虾三级) | 2018-12-20 16:53
0

原因找到了,是因为同事在注入DbContext时,把DbContext声明为静态的了,并发时造成了线程不安全的DbContext的替换。在此提醒各位,请合理使用依赖注入。

chester·chen | 园豆:507 (小虾三级) | 2018-12-21 17:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册