mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 修复 BaseEntity 子查询 .Where 问题;#1586
This commit is contained in:
@ -1255,31 +1255,34 @@ namespace FreeSql.Internal
|
||||
}
|
||||
}
|
||||
}
|
||||
if (new[] { "Where", "WhereIf" }.Contains(exp3tmpCall.Method.Name) && exp3tmpCall.Object != null)
|
||||
if (new[] { "Where", "WhereIf" }.Contains(exp3tmpCall.Method.Name))
|
||||
{
|
||||
//这段特别兼容 DbSet.Where 表达式解析 #216
|
||||
var exp3tmpTestCall = Expression.Call(exp3tmpCall.Object, exp3tmpCall.Method, exp3tmpCall.Arguments.Select(a =>
|
||||
//if (exp3tmpCall.Object != null) //BaseEntity.Where 也需要兼容
|
||||
{
|
||||
var a2 = a;
|
||||
if (a2.NodeType == ExpressionType.Quote) a2 = (a as UnaryExpression)?.Operand;
|
||||
if (a2?.NodeType == ExpressionType.Lambda)
|
||||
//这段特别兼容 DbSet.Where 表达式解析 #216
|
||||
var exp3tmpTestCall = Expression.Call(exp3tmpCall.Object, exp3tmpCall.Method, exp3tmpCall.Arguments.Select(a =>
|
||||
{
|
||||
var alambda = a2 as LambdaExpression;
|
||||
if (alambda.ReturnType == typeof(bool))
|
||||
return Expression.Constant(null, a.Type);// Expression.Lambda(Expression.Constant(true), alambda.Parameters);
|
||||
}
|
||||
return a;
|
||||
//if (a.Type == typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(exp3tmp.Type.GetGenericArguments()[0], typeof(bool))))
|
||||
// return Expression.Lambda(Expression.Constant(true),
|
||||
}).ToArray());
|
||||
fsql = Expression.Lambda(exp3tmpTestCall).Compile().DynamicInvoke();
|
||||
var fsqlFindMethod = fsql.GetType().GetMethod(exp3tmpCall.Method.Name, exp3tmpCall.Arguments.Select(a => a.Type).ToArray());
|
||||
if (fsqlFindMethod == null)
|
||||
throw new Exception(CoreStrings.Unable_Parse_ExpressionMethod(exp3tmpCall.Method.Name));
|
||||
var exp3StackOld = exp3Stack;
|
||||
exp3Stack = new Stack<Expression>();
|
||||
exp3Stack.Push(Expression.Call(Expression.Constant(fsql), fsqlFindMethod, exp3tmpCall.Arguments));
|
||||
while (exp3StackOld.Any()) exp3Stack.Push(exp3StackOld.Pop());
|
||||
var a2 = a;
|
||||
if (a2.NodeType == ExpressionType.Quote) a2 = (a as UnaryExpression)?.Operand;
|
||||
if (a2?.NodeType == ExpressionType.Lambda)
|
||||
{
|
||||
var alambda = a2 as LambdaExpression;
|
||||
if (alambda.ReturnType == typeof(bool))
|
||||
return Expression.Constant(null, a.Type);// Expression.Lambda(Expression.Constant(true), alambda.Parameters);
|
||||
}
|
||||
return a;
|
||||
//if (a.Type == typeof(Expression<>).MakeGenericType(typeof(Func<,>).MakeGenericType(exp3tmp.Type.GetGenericArguments()[0], typeof(bool))))
|
||||
// return Expression.Lambda(Expression.Constant(true),
|
||||
}).ToArray());
|
||||
fsql = Expression.Lambda(exp3tmpTestCall).Compile().DynamicInvoke();
|
||||
var fsqlFindMethod = fsql.GetType().GetMethod(exp3tmpCall.Method.Name, exp3tmpCall.Arguments.Select(a => a.Type).ToArray());
|
||||
if (fsqlFindMethod == null)
|
||||
throw new Exception(CoreStrings.Unable_Parse_ExpressionMethod(exp3tmpCall.Method.Name));
|
||||
var exp3StackOld = exp3Stack;
|
||||
exp3Stack = new Stack<Expression>();
|
||||
exp3Stack.Push(Expression.Call(Expression.Constant(fsql), fsqlFindMethod, exp3tmpCall.Arguments));
|
||||
while (exp3StackOld.Any()) exp3Stack.Push(exp3StackOld.Pop());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fsql == null)
|
||||
|
Reference in New Issue
Block a user