mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复 v3.2.688 WithTempQuery 场景的 DTO 映射查询;
This commit is contained in:
parent
74567733a7
commit
62408b2ba7
@ -330,7 +330,10 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (diymemexp != null && dtTb.Parameter != null)
|
||||
{
|
||||
var dbTbExp = MatchDtoProperty(dtTb, dtoProp);
|
||||
var isBreaked = false;
|
||||
var dbTbExps = MatchDtoPropertys(dtTb, dtoProp); //嵌套查询临时类,可能匹配到多个 DTO
|
||||
foreach (var dbTbExp in dbTbExps)
|
||||
{
|
||||
if (dbTbExp?.Any() == true)
|
||||
{
|
||||
var dbfield = diymemexp.ParseExp(dbTbExp);
|
||||
@ -352,10 +355,13 @@ namespace FreeSql.Internal
|
||||
diychild.DbNestedField = $"as{++index}";
|
||||
field.Append(_common.FieldAsAlias(diychild.DbNestedField));
|
||||
}
|
||||
isBreaked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isBreaked) break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (trydtocol.Attribute.IsIgnore == true) continue;
|
||||
@ -456,7 +462,10 @@ namespace FreeSql.Internal
|
||||
{
|
||||
if (diymemexp != null && dtTb.Parameter != null)
|
||||
{
|
||||
var dbTbExp = MatchDtoProperty(dtTb, dtoProp);
|
||||
var isBreaked = false;
|
||||
var dbTbExps = MatchDtoPropertys(dtTb, dtoProp); //嵌套查询临时类,可能匹配到多个 DTO
|
||||
foreach (var dbTbExp in dbTbExps)
|
||||
{
|
||||
if (dbTbExp?.Any() == true)
|
||||
{
|
||||
var dbfield = diymemexp.ParseExp(dbTbExp);
|
||||
@ -478,10 +487,13 @@ namespace FreeSql.Internal
|
||||
diychild.DbNestedField = $"as{++index}";
|
||||
field.Append(_common.FieldAsAlias(diychild.DbNestedField));
|
||||
}
|
||||
isBreaked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isBreaked) break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (trydtocol.Attribute.IsIgnore == true) continue;
|
||||
@ -2498,20 +2510,12 @@ namespace FreeSql.Internal
|
||||
//return string.Concat(_ado.AddslashesProcessParam(obj, mapType, mapColumn));
|
||||
}
|
||||
|
||||
public static Expression[] MatchDtoProperty(SelectTableInfo tb, PropertyInfo dtoProp)
|
||||
public List<Expression[]> MatchDtoPropertys(SelectTableInfo tb, PropertyInfo dtoProp)
|
||||
{
|
||||
if (tb == null || dtoProp == null || tb.Parameter == null) return null;
|
||||
var exp = LocalMatch(tb.Parameter.Type, tb.Parameter);
|
||||
if (exp == null) return null;
|
||||
var exps = new Stack<Expression>();
|
||||
while (true)
|
||||
{
|
||||
exps.Push(exp);
|
||||
exp = (exp as MemberExpression).Expression;
|
||||
if (exp.NodeType == ExpressionType.Parameter) break;
|
||||
}
|
||||
if (exps.Any()) return exps.ToArray();
|
||||
return null;
|
||||
var retList = new List<Expression[]>();
|
||||
LocalMatch(tb.Parameter.Type, tb.Parameter);
|
||||
return retList;
|
||||
|
||||
Expression LocalMatch(Type type, Expression memExp)
|
||||
{
|
||||
@ -2522,12 +2526,32 @@ namespace FreeSql.Internal
|
||||
{
|
||||
foreach (var typeProp in typeProps.Values)
|
||||
{
|
||||
if (Utils.dicExecuteArrayRowReadClassOrTuple.ContainsKey(type)) return null;
|
||||
if (Utils.dicExecuteArrayRowReadClassOrTuple.ContainsKey(typeProp.PropertyType)) continue;
|
||||
if (typeProp.PropertyType.IsAnonymousType() || _common.GetTableByEntity(typeProp.PropertyType)?.Columns.Any() == true)
|
||||
{
|
||||
var nextExp = Expression.MakeMemberAccess(memExp, typeProp);
|
||||
var ret = LocalMatch(typeProp.PropertyType, nextExp);
|
||||
if (ret != null) return ret;
|
||||
if (ret != null)
|
||||
{
|
||||
var expPath = LocalGetExpressionPath(ret);
|
||||
if (expPath != null) retList.Add(expPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Expression[] LocalGetExpressionPath(Expression exp)
|
||||
{
|
||||
if (exp == null) return null;
|
||||
var exps = new Stack<Expression>();
|
||||
while (true)
|
||||
{
|
||||
exps.Push(exp);
|
||||
exp = (exp as MemberExpression).Expression;
|
||||
if (exp.NodeType == ExpressionType.Parameter) break;
|
||||
}
|
||||
if (exps.Any()) return exps.ToArray();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user