mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 修复 Enum -> MapType(string) + GroupBy 解析问题;#1727
This commit is contained in:
@ -26,6 +26,7 @@ namespace FreeSql.Internal
|
||||
public ReadAnonymousTypeInfo _map;
|
||||
public string _field;
|
||||
public ReadAnonymousTypeInfo ParseExpMapResult { get; internal protected set; }
|
||||
public ColumnInfo ParseExpColumnResult { get; internal protected set; }
|
||||
public abstract string ParseExp(Expression[] members);
|
||||
}
|
||||
|
||||
@ -859,10 +860,10 @@ namespace FreeSql.Internal
|
||||
}
|
||||
|
||||
Type oldMapType = null;
|
||||
if (tsc.diymemexp != null) tsc.diymemexp.ParseExpMapResult = null;
|
||||
if (tsc.diymemexp != null) tsc.diymemexp.ParseExpColumnResult = null;
|
||||
var left = ExpressionLambdaToSql(leftExp, tsc);
|
||||
var leftMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, left) ??
|
||||
(tsc.diymemexp?.ParseExpMapResult?.Table?.ColumnsByCs.TryGetValue(tsc.diymemexp.ParseExpMapResult.CsName, out var dmcol) == true ? dmcol : null); //group by emum -> MapType(string) #1727
|
||||
tsc.diymemexp?.ParseExpColumnResult; //group by emum -> MapType(string) #1727
|
||||
var isLeftMapType = leftMapColumn != null && new[] { "AND", "OR", "*", "/", "+", "-" }.Contains(oper) == false && (leftMapColumn.Attribute.MapType != rightExp.Type || leftMapColumn.CsType != rightExp.Type);
|
||||
ColumnInfo rightMapColumn = null;
|
||||
var isRightMapType = false;
|
||||
|
@ -241,6 +241,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public override string ParseExp(Expression[] members)
|
||||
{
|
||||
ParseExpMapResult = null;
|
||||
ParseExpColumnResult = null;
|
||||
ParseExpMatchedTable = GetOutsideSelectTable(members.FirstOrDefault()?.GetParameter());
|
||||
if (ParseExpMatchedTable == null) return null;
|
||||
|
||||
@ -254,12 +255,14 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (members.Any() == false)
|
||||
{
|
||||
ParseExpMapResult = insideData.InsideMap;
|
||||
ParseExpColumnResult = ParseExpMapResult.GetColumn();
|
||||
return $"{ParseExpMatchedTable.Alias}.{insideData.InsideMap.DbNestedField}";
|
||||
}
|
||||
var read = insideData.InsideMap;
|
||||
if (members.Length == 1 && members[0] == ParseExpMatchedTable.Parameter)
|
||||
{
|
||||
ParseExpMapResult = read;
|
||||
ParseExpColumnResult = ParseExpMapResult.GetColumn();
|
||||
return $"{ParseExpMatchedTable.Alias}.{read.DbNestedField}";
|
||||
}
|
||||
for (var a = members[0] == ParseExpMatchedTable.Parameter ? 1 : 0; a < members.Length; a++)
|
||||
@ -268,6 +271,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (read == null) return null;
|
||||
}
|
||||
ParseExpMapResult = read;
|
||||
ParseExpColumnResult = ParseExpMapResult.GetColumn();
|
||||
return $"{ParseExpMatchedTable.Alias}.{read.DbNestedField}";
|
||||
}
|
||||
public SelectTableInfo GetOutsideSelectTable(ParameterExpression parameterExp)
|
||||
|
@ -36,9 +36,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public override string ParseExp(Expression[] members)
|
||||
{
|
||||
ParseExpMapResult = null;
|
||||
ParseExpColumnResult = null;
|
||||
if (members.Any() == false)
|
||||
{
|
||||
ParseExpMapResult = _map;
|
||||
ParseExpColumnResult = ParseExpMapResult.GetColumn();
|
||||
return _map.DbField;
|
||||
}
|
||||
var firstMember = ((members.FirstOrDefault() as MemberExpression)?.Expression as MemberExpression);
|
||||
@ -53,6 +55,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (read == null) return null;
|
||||
}
|
||||
ParseExpMapResult = read;
|
||||
ParseExpColumnResult = ParseExpMapResult.GetColumn();
|
||||
if (!_addFieldAlias) return read.DbField;
|
||||
if (_flagNestedFieldAlias) return read.DbField;
|
||||
if (_comonExp.EndsWithDbNestedField(read.DbField, read.DbNestedField) == false)
|
||||
@ -82,6 +85,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
members[a] = replaceVistor.Modify(members[a], replaceMember, curtable.Parameter);
|
||||
var ret = _select._diymemexpWithTempQuery.ParseExp(members);
|
||||
ParseExpMapResult = _select._diymemexpWithTempQuery.ParseExpMapResult;
|
||||
ParseExpColumnResult = ParseExpMapResult.GetColumn();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -132,16 +136,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
var tsc = new CommonExpression.ExpTSC { _tables = _tables, _tableRule = _select._tableRule, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = true, style = CommonExpression.ExpressionStyle.Where };
|
||||
var result = _comonExp.ExpressionLambdaToSql(retExp, tsc);
|
||||
//ParseExpMapResult = result
|
||||
if (tsc.mapColumnTmp != null)
|
||||
ParseExpMapResult = new ReadAnonymousTypeInfo
|
||||
{
|
||||
Property = tsc.mapColumnTmp.Table.Properties[tsc.mapColumnTmp.CsName],
|
||||
CsName = tsc.mapColumnTmp.CsName,
|
||||
CsType = tsc.mapColumnTmp.CsType, //dtoProp.PropertyType,
|
||||
MapType = tsc.mapColumnTmp.Attribute.MapType,
|
||||
Table = tsc.mapColumnTmp.Table
|
||||
};
|
||||
ParseExpColumnResult = tsc.mapColumnTmp;
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
|
@ -25,6 +25,12 @@ namespace FreeSql.Internal.Model
|
||||
public string IncludeManyKey { get; set; } //ToList(a => new { a.Childs }) 集合属性指定加载
|
||||
public Expression SubSelectMany { get; set; } //ToList(a => new { sublist = fsql.Select<T>().ToList() }) 子集合查询
|
||||
|
||||
public ColumnInfo GetColumn()
|
||||
{
|
||||
if (Childs.Any() == false && Table != null && CsName != null && Table.ColumnsByCs.TryGetValue(CsName, out var pcol)) return pcol;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void CopyTo(ReadAnonymousTypeInfo target)
|
||||
{
|
||||
target.Property = Property;
|
||||
|
Reference in New Issue
Block a user