mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
- 优化 ToSql 别名大小写问题;#467
This commit is contained in:
parent
390be18506
commit
b193d86aa4
@ -502,14 +502,5 @@
|
|||||||
<param name="that"></param>
|
<param name="that"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
|
||||||
<summary>
|
|
||||||
批量注入 Repository,可以参考代码自行调整
|
|
||||||
</summary>
|
|
||||||
<param name="services"></param>
|
|
||||||
<param name="globalDataFilter"></param>
|
|
||||||
<param name="assemblies"></param>
|
|
||||||
<returns></returns>
|
|
||||||
</member>
|
|
||||||
</members>
|
</members>
|
||||||
</doc>
|
</doc>
|
||||||
|
@ -1126,12 +1126,12 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
|||||||
WF_ProcessInstance = p
|
WF_ProcessInstance = p
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
Assert.Equal(@"SELECT max(a.`Id`) `TaskId`, max(a.`Type`) `TaskType`, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
||||||
FROM `WF_Task` a
|
FROM `WF_Task` a
|
||||||
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
||||||
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
|
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
|
||||||
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
|
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
|
||||||
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
FROM ( SELECT max(a.`Id`) `TaskId`, max(a.`Type`) `TaskType`, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
||||||
FROM `WF_Task` a
|
FROM `WF_Task` a
|
||||||
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
||||||
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
|
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
|
||||||
|
@ -1137,12 +1137,12 @@ WHERE (((cast(a.`Id` as char)) in (SELECT b.`Title`
|
|||||||
WF_ProcessInstance = p
|
WF_ProcessInstance = p
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
Assert.Equal(@"SELECT max(a.`Id`) `TaskId`, max(a.`Type`) `TaskType`, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
||||||
FROM `WF_Task` a
|
FROM `WF_Task` a
|
||||||
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
||||||
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
|
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
|
||||||
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
|
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
|
||||||
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
FROM ( SELECT max(a.`Id`) `TaskId`, max(a.`Type`) `TaskType`, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
||||||
FROM `WF_Task` a
|
FROM `WF_Task` a
|
||||||
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
||||||
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
|
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
|
||||||
|
@ -22,7 +22,7 @@ namespace FreeSql.Tests.Issues
|
|||||||
Name = w.Address,
|
Name = w.Address,
|
||||||
No = w.Number.ToString()
|
No = w.Number.ToString()
|
||||||
}, FieldAliasOptions.AsProperty);
|
}, FieldAliasOptions.AsProperty);
|
||||||
Assert.Equal(@"SELECT cast(a.""Number"" as character) CardNumber, ((a.""CommType"" + 1)) CardType, a.""Address"" Name, cast(a.""Number"" as character) No
|
Assert.Equal(@"SELECT cast(a.""Number"" as character) ""CardNumber"", ((a.""CommType"" + 1)) ""CardType"", a.""Address"" ""Name"", cast(a.""Number"" as character) ""No""
|
||||||
FROM ""WorkSite"" a", sql);
|
FROM ""WorkSite"" a", sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1206,12 +1206,12 @@ limit 0,20", select
|
|||||||
WF_ProcessInstance = p
|
WF_ProcessInstance = p
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.Equal(@"SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
Assert.Equal(@"SELECT max(a.`Id`) `TaskId`, max(a.`Type`) `TaskType`, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
||||||
FROM `WF_Task` a
|
FROM `WF_Task` a
|
||||||
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
||||||
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
|
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName`", sqltmp12);
|
||||||
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
|
Assert.Equal(@"SELECT a.`TaskId` as1, a.`TaskType` as2, a.`ProcessId` as3, a.`NodeId` as4, a.`NodeName` as5, b.`Id` as6, b.`TaskType` as7, b.`ProcessId` as8, b.`NodeId` as9, b.`CreateTime` as10, b.`IsFinished` as11, b.`EnabledMark` as12
|
||||||
FROM ( SELECT max(a.`Id`) TaskId, max(a.`Type`) TaskType, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
FROM ( SELECT max(a.`Id`) `TaskId`, max(a.`Type`) `TaskType`, a.`ProcessId`, a.`NodeId`, a.`NodeName`
|
||||||
FROM `WF_Task` a
|
FROM `WF_Task` a
|
||||||
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
WHERE (a.`IsFinished` = 1 AND (a.`AuditorId` = '1' OR a.`AuditorId` = '1cb71584-a6dd-4b26-8c88-ed9fb8cf87a3'))
|
||||||
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
|
GROUP BY a.`ProcessId`, a.`NodeId`, a.`NodeName` ) a
|
||||||
|
@ -35,6 +35,13 @@ namespace FreeSql.Internal
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal const int ReadAnonymousFieldAsCsName = -53129;
|
internal const int ReadAnonymousFieldAsCsName = -53129;
|
||||||
|
internal string GetFieldAsCsName(string csname)
|
||||||
|
{
|
||||||
|
csname = _common.QuoteSqlName(csname);
|
||||||
|
if (_common.CodeFirst.IsSyncStructureToLower) csname = csname.ToLower();
|
||||||
|
if (_common.CodeFirst.IsSyncStructureToUpper) csname = csname.ToUpper();
|
||||||
|
return csname;
|
||||||
|
}
|
||||||
public bool ReadAnonymousField(List<SelectTableInfo> _tables, StringBuilder field, ReadAnonymousTypeInfo parent, ref int index, Expression exp, Select0Provider select, BaseDiyMemberExpression diymemexp, List<GlobalFilter.Item> whereGlobalFilter, List<string> findIncludeMany, bool isAllDtoMap)
|
public bool ReadAnonymousField(List<SelectTableInfo> _tables, StringBuilder field, ReadAnonymousTypeInfo parent, ref int index, Expression exp, Select0Provider select, BaseDiyMemberExpression diymemexp, List<GlobalFilter.Item> whereGlobalFilter, List<string> findIncludeMany, bool isAllDtoMap)
|
||||||
{
|
{
|
||||||
Func<ExpTSC> getTSC = () => new ExpTSC { _tables = _tables, diymemexp = diymemexp, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Where, whereGlobalFilter = whereGlobalFilter, dbParams = select?._params }; //#462 添加 DbParams 解决
|
Func<ExpTSC> getTSC = () => new ExpTSC { _tables = _tables, diymemexp = diymemexp, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = false, style = ExpressionStyle.Where, whereGlobalFilter = whereGlobalFilter, dbParams = select?._params }; //#462 添加 DbParams 解决
|
||||||
@ -47,7 +54,7 @@ namespace FreeSql.Internal
|
|||||||
parent.DbField = $"-({ExpressionLambdaToSql(exp, getTSC())})";
|
parent.DbField = $"-({ExpressionLambdaToSql(exp, getTSC())})";
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(GetFieldAsCsName(parent.CsName)));
|
||||||
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
||||||
return false;
|
return false;
|
||||||
case ExpressionType.Convert: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand, select, diymemexp, whereGlobalFilter, findIncludeMany, isAllDtoMap);
|
case ExpressionType.Convert: return ReadAnonymousField(_tables, field, parent, ref index, (exp as UnaryExpression)?.Operand, select, diymemexp, whereGlobalFilter, findIncludeMany, isAllDtoMap);
|
||||||
@ -67,7 +74,7 @@ namespace FreeSql.Internal
|
|||||||
parent.DbField = _common.FormatSql("{0}", constExp?.Value);
|
parent.DbField = _common.FormatSql("{0}", constExp?.Value);
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(GetFieldAsCsName(parent.CsName)));
|
||||||
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
||||||
return false;
|
return false;
|
||||||
case ExpressionType.Conditional:
|
case ExpressionType.Conditional:
|
||||||
@ -90,7 +97,7 @@ namespace FreeSql.Internal
|
|||||||
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(GetFieldAsCsName(parent.CsName)));
|
||||||
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
||||||
return false;
|
return false;
|
||||||
case ExpressionType.Parameter:
|
case ExpressionType.Parameter:
|
||||||
@ -187,9 +194,12 @@ namespace FreeSql.Internal
|
|||||||
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
parent.DbField = ExpressionLambdaToSql(exp, getTSC());
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false &&
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false)
|
||||||
parent.DbField.EndsWith(_common.QuoteSqlName(parent.CsName), StringComparison.CurrentCultureIgnoreCase) == false //DbField 和 CsName 相同的时候,不处理
|
{
|
||||||
) field.Append(_common.FieldAsAlias(parent.CsName));
|
var csname = GetFieldAsCsName(parent.CsName);
|
||||||
|
if (parent.DbField.EndsWith(csname, StringComparison.CurrentCultureIgnoreCase) == false) //DbField 和 CsName 相同的时候,不处理
|
||||||
|
field.Append(_common.FieldAsAlias(csname));
|
||||||
|
}
|
||||||
if (parent.MapType == null) parent.MapType = SearchColumnByField(_tables, null, parent.DbField)?.Attribute.MapType ?? exp.Type;
|
if (parent.MapType == null) parent.MapType = SearchColumnByField(_tables, null, parent.DbField)?.Attribute.MapType ?? exp.Type;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -336,7 +346,7 @@ namespace FreeSql.Internal
|
|||||||
parent.DbField = $"({ExpressionLambdaToSql(exp, getTSC())})";
|
parent.DbField = $"({ExpressionLambdaToSql(exp, getTSC())})";
|
||||||
field.Append(", ").Append(parent.DbField);
|
field.Append(", ").Append(parent.DbField);
|
||||||
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
if (index >= 0) field.Append(_common.FieldAsAlias($"as{++index}"));
|
||||||
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(parent.CsName));
|
else if (index == ReadAnonymousFieldAsCsName && string.IsNullOrEmpty(parent.CsName) == false) field.Append(_common.FieldAsAlias(GetFieldAsCsName(parent.CsName)));
|
||||||
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
if (parent.CsType == null && exp.Type.IsValueType) parent.CsType = exp.Type;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user