修复 SqlServer 工作单元 bug #23

需要同时设置 SqlCommand.Connection + Transaction
This commit is contained in:
28810 2019-04-19 13:50:19 +08:00
parent acc1754e2e
commit e3c0f615f9
3 changed files with 15 additions and 4 deletions

View File

@ -43,9 +43,7 @@ namespace FreeSql.Extensions.EntityUtil {
for (var a = 0; a < pks.Length; a++) { for (var a = 0; a < pks.Length; a++) {
var isguid = pks[a].CsType.NullableTypeOrThis() == typeof(Guid); var isguid = pks[a].CsType.NullableTypeOrThis() == typeof(Guid);
Expression expthen = null; Expression expthen = null;
if (isguid == false) if (isguid) {
expthen = Expression.Assign(var3IsNull, Expression.Constant(true));
else {
expthen = Expression.Block( expthen = Expression.Block(
new Expression[]{ new Expression[]{
Expression.Assign(Expression.MakeMemberAccess(var1Parm, _table.Properties[pks[a].CsName]), Expression.Call(MethodFreeUtilNewMongodbId)), Expression.Assign(Expression.MakeMemberAccess(var1Parm, _table.Properties[pks[a].CsName]), Expression.Call(MethodFreeUtilNewMongodbId)),
@ -55,6 +53,17 @@ namespace FreeSql.Extensions.EntityUtil {
) )
}.Where(c => c != null).ToArray() }.Where(c => c != null).ToArray()
); );
} else if (pks.Length > 1 && pks[a].Attribute.IsIdentity) {
expthen = Expression.Block(
new Expression[]{
a > 0 ? Expression.Call(var2Sb, MethodStringBuilderAppend, Expression.Constant(splitString)) : null,
Expression.Call(var2Sb, MethodStringBuilderAppend,
Expression.Convert(Expression.MakeMemberAccess(var1Parm, _table.Properties[pks[a].CsName]), typeof(object))
)
}.Where(c => c != null).ToArray()
);
} else {
expthen = Expression.Assign(var3IsNull, Expression.Constant(true));
} }
if (pks[a].Attribute.IsIdentity || isguid || pks[a].CsType == typeof(string) || pks[a].CsType.IsNullableType()) { if (pks[a].Attribute.IsIdentity || isguid || pks[a].CsType == typeof(string) || pks[a].CsType.IsNullableType()) {
exps.Add( exps.Add(

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>0.5.1.3</Version> <Version>0.5.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>YeXiangQin</Authors> <Authors>YeXiangQin</Authors>
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description> <Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>

View File

@ -323,6 +323,8 @@ namespace FreeSql.Internal.CommonProvider {
isclose = true; isclose = true;
} }
cmd.Connection = connection; cmd.Connection = connection;
if (transaction.Connection == connection)
cmd.Transaction = transaction;
} }
if (IsTracePerformance) dt = DateTime.Now; if (IsTracePerformance) dt = DateTime.Now;