mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 优化 表达式 true && ... 解析的处理;
- 优化 Navigate 指定联合键关系时,对属性顺序的要求,当类型不一样、名称一样时无须指明属性的顺序,如:[Navigate("MemberId, ShopId")];
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
|
||||
<Version>0.7.5</Version>
|
||||
<Version>0.7.6</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||
|
@ -327,16 +327,7 @@ namespace FreeSql.Internal
|
||||
if (exp.NodeType == ExpressionType.MemberAccess && isBool && sql.Contains(" IS ") == false && sql.Contains(" = ") == false)
|
||||
return $"{sql} = {formatSql(true, null)}";
|
||||
if (isBool)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": return "1=1";
|
||||
case "0":
|
||||
case "'f'": return "1=2";
|
||||
default: return sql;
|
||||
}
|
||||
}
|
||||
return GetBoolString(sql);
|
||||
return sql;
|
||||
}
|
||||
|
||||
@ -347,16 +338,7 @@ namespace FreeSql.Internal
|
||||
if (exp.NodeType == ExpressionType.MemberAccess && isBool && sql.Contains(" IS ") == false && sql.Contains(" = ") == false)
|
||||
return $"{sql} = {formatSql(true, null)}";
|
||||
if (isBool)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": return "1=1";
|
||||
case "0":
|
||||
case "'f'": return "1=2";
|
||||
default: return sql;
|
||||
}
|
||||
}
|
||||
return GetBoolString(sql);
|
||||
return sql;
|
||||
}
|
||||
public void ExpressionJoinLambda(List<SelectTableInfo> _tables, SelectTableInfoType tbtype, Expression exp, Func<Expression[], string> getSelectGroupingMapString)
|
||||
@ -367,16 +349,8 @@ namespace FreeSql.Internal
|
||||
if (exp.NodeType == ExpressionType.MemberAccess && isBool && sql.Contains(" IS ") == false && sql.Contains(" = ") == false)
|
||||
sql = $"{sql} = {formatSql(true, null)}";
|
||||
if (isBool)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": sql = "1=1"; break;
|
||||
case "0":
|
||||
case "'f'": sql = "1=2"; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
sql = GetBoolString(sql);
|
||||
|
||||
if (_tables.Count > tbidx)
|
||||
{
|
||||
_tables[tbidx].Type = tbtype;
|
||||
@ -403,6 +377,17 @@ namespace FreeSql.Internal
|
||||
static MethodInfo MethodDateTimeSubtractDateTime = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(DateTime) });
|
||||
static MethodInfo MethodDateTimeSubtractTimeSpan = typeof(DateTime).GetMethod("Subtract", new Type[] { typeof(TimeSpan) });
|
||||
|
||||
static string GetBoolString(string sql)
|
||||
{
|
||||
switch (sql)
|
||||
{
|
||||
case "1":
|
||||
case "'t'": return "1=1";
|
||||
case "0":
|
||||
case "'f'": return "1=2";
|
||||
default: return sql;
|
||||
}
|
||||
}
|
||||
public string ExpressionBinary(string oper, Expression leftExp, Expression rightExp, ExpTSC tsc)
|
||||
{
|
||||
switch (oper)
|
||||
@ -483,7 +468,15 @@ namespace FreeSql.Internal
|
||||
left = tmp;
|
||||
}
|
||||
if (right == "NULL") oper = oper == "=" ? " IS " : " IS NOT ";
|
||||
if (oper == "%") return _common.Mod(left, right, leftExp.Type, rightExp.Type);
|
||||
switch(oper)
|
||||
{
|
||||
case "%": return _common.Mod(left, right, leftExp.Type, rightExp.Type);
|
||||
case "AND":
|
||||
case "OR":
|
||||
left = GetBoolString(left);
|
||||
right = GetBoolString(right);
|
||||
break;
|
||||
}
|
||||
tsc.mapType = null;
|
||||
return $"{left} {oper} {right}";
|
||||
}
|
||||
|
@ -568,6 +568,19 @@ namespace FreeSql.Internal
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
if (trytb.Primarys.Length > 1)
|
||||
{
|
||||
if (trytb.Primarys.Select(a => a.CsType).Distinct().Count() == trytb.Primarys.Length)
|
||||
{
|
||||
var pkList = trytb.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType == a.CsType).CompareTo(pkList.FindIndex(c => c.CsType == b.CsType)));
|
||||
}
|
||||
else if (string.Compare(string.Join(",", trytb.Primarys.Select(a => a.CsName).OrderBy(a => a)), string.Join(",", bindColumns.Select(a => a.CsName).OrderBy(a => a)), true) == 0)
|
||||
{
|
||||
var pkList = trytb.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => string.Compare(c.CsName, a.CsName, true) == 0).CompareTo(pkList.FindIndex(c => string.Compare(c.CsName, b.CsName, true) == 0)));
|
||||
}
|
||||
}
|
||||
for (var a = 0; nvref.Exception == null && a < trytb.Primarys.Length; a++)
|
||||
{
|
||||
var findtrytbPkCsName = trytb.Primarys[a].CsName.TrimStart('_');
|
||||
@ -705,6 +718,19 @@ namespace FreeSql.Internal
|
||||
trytb.AddOrUpdateTableRef(pnv.Name, nvref);
|
||||
//if (isLazy) throw nvref.Exception;
|
||||
}
|
||||
if (tbref.Primarys.Length > 1)
|
||||
{
|
||||
if (tbref.Primarys.Select(a => a.CsType).Distinct().Count() == tbref.Primarys.Length)
|
||||
{
|
||||
var pkList = tbref.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => c.CsType == a.CsType).CompareTo(pkList.FindIndex(c => c.CsType == b.CsType)));
|
||||
}
|
||||
else if (string.Compare(string.Join(",", tbref.Primarys.Select(a => a.CsName).OrderBy(a => a)), string.Join(",", bindColumns.Select(a => a.CsName).OrderBy(a => a)), true) == 0)
|
||||
{
|
||||
var pkList = tbref.Primarys.ToList();
|
||||
bindColumns.Sort((a, b) => pkList.FindIndex(c => string.Compare(c.CsName, a.CsName, true) == 0).CompareTo(pkList.FindIndex(c => string.Compare(c.CsName, b.CsName, true) == 0)));
|
||||
}
|
||||
}
|
||||
for (var a = 0; nvref.Exception == null && a < tbref.Primarys.Length; a++)
|
||||
{
|
||||
var findtbrefPkCsName = tbref.Primarys[a].CsName.TrimStart('_');
|
||||
|
Reference in New Issue
Block a user