问题描述
private bool _updateList(SysInfo _sysInfo,List< pList> ; _pList)
{
try
{
foreach(_ pList中的var p)
{
_context.spUpdatePListApprovalFlow(p.countryID, _sysInfo.User.JobRoleID,p.src,p.id,p.status,_sysInfo.User.Username);
}
返回true;
}
catch(Exception ex)//仅调试
{
throw; //抛出错误到主要尝试catch
}
}
错误
但是,当我在SQL管理中运行存储过程时,一切正常Studio:
exec [dbo]。[spUpdatePListApprovalFlow]
@CountryID = 123456,
@UserTypeID = 23456,
@Src = 1,
@Id ='123456789',
@Status = 30,
@Username ='username'
我厌倦了挖掘一个答案没有任何作用...我尝试过的很少的东西:
- SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
- 在存储过程中插入多个事务
这是p上有2个子存储过程。一个写入应用程序数据库的表,另一个更新为as400中的表。
在EF6存储过程中默认情况下,在显式事务中调用。您可以通过在创建它之后更改其配置,或通过在构造函数中更改DbContext类型的所有实例来关闭特定的DbContext实例。 EG
using(var db = new Db())
{
db.Configuration.EnsureTransactionsForFunctionsAndCommands =假;
//。 。 。
}
请参阅:
I'm having the following error executing this piece of code:
private bool _updateList(SysInfo _sysInfo, List<pList> _pList)
{
try
{
foreach (var p in _pList)
{
_context.spUpdatePListApprovalFlow(p.countryID, _sysInfo.User.JobRoleID, p.src, p.id, p.status, _sysInfo.User.Username);
}
return true;
}
catch (Exception ex) //debug only
{
throw; //throws error to the main try catch
}
}
ERROR
However, everything works fine when I run the Stored Procedure in SQL Management Studio:
exec [dbo].[spUpdatePListApprovalFlow]
@CountryID = 123456,
@UserTypeID = 23456,
@Src = 1,
@Id = '123456789',
@Status = 30,
@Username = 'username'
I'm tired of digging for an answer nothing works... Few things I've tried:
- SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
- insert multiple transactions in the stored procedure
This sp has 2 sub stored procedures on it. One that writes into a table of the application's database, and another that updates a table in as400.
In EF6 stored procedures are called in an explicit transaction, by default. You can turn this off for a particular DbContext instance by changing its configuration after creating it, or for all instances of a DbContext type by changing it in the constructor. EG
using (var db = new Db())
{
db.Configuration.EnsureTransactionsForFunctionsAndCommands = false;
//. . .
}
这篇关于无法使用Entiy Framework开始分布式事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!