Skip to content

Commit e3c0f61

Browse files
2881028810
28810
authored and
28810
committed
修复 SqlServer 工作单元 bug #23
需要同时设置 SqlCommand.Connection + Transaction
1 parent acc1754 commit e3c0f61

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

FreeSql/Extensions/EntityUtilExtensions.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public static string GetEntityKeyString(this IFreeSql orm, Type entityType, obje
4343
for (var a = 0; a < pks.Length; a++) {
4444
var isguid = pks[a].CsType.NullableTypeOrThis() == typeof(Guid);
4545
Expression expthen = null;
46-
if (isguid == false)
47-
expthen = Expression.Assign(var3IsNull, Expression.Constant(true));
48-
else {
46+
if (isguid) {
4947
expthen = Expression.Block(
5048
new Expression[]{
5149
Expression.Assign(Expression.MakeMemberAccess(var1Parm, _table.Properties[pks[a].CsName]), Expression.Call(MethodFreeUtilNewMongodbId)),
@@ -55,6 +53,17 @@ public static string GetEntityKeyString(this IFreeSql orm, Type entityType, obje
5553
)
5654
}.Where(c => c != null).ToArray()
5755
);
56+
} else if (pks.Length > 1 && pks[a].Attribute.IsIdentity) {
57+
expthen = Expression.Block(
58+
new Expression[]{
59+
a > 0 ? Expression.Call(var2Sb, MethodStringBuilderAppend, Expression.Constant(splitString)) : null,
60+
Expression.Call(var2Sb, MethodStringBuilderAppend,
61+
Expression.Convert(Expression.MakeMemberAccess(var1Parm, _table.Properties[pks[a].CsName]), typeof(object))
62+
)
63+
}.Where(c => c != null).ToArray()
64+
);
65+
} else {
66+
expthen = Expression.Assign(var3IsNull, Expression.Constant(true));
5867
}
5968
if (pks[a].Attribute.IsIdentity || isguid || pks[a].CsType == typeof(string) || pks[a].CsType.IsNullableType()) {
6069
exps.Add(

FreeSql/FreeSql.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Version>0.5.1.3</Version>
5+
<Version>0.5.2</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>YeXiangQin</Authors>
88
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>

FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs

+2
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ public object ExecuteScalar(DbConnection connection, DbTransaction transaction,
323323
isclose = true;
324324
}
325325
cmd.Connection = connection;
326+
if (transaction.Connection == connection)
327+
cmd.Transaction = transaction;
326328
}
327329

328330
if (IsTracePerformance) dt = DateTime.Now;

0 commit comments

Comments
 (0)