当应用ToList
时,始终抛出此异常
值不能为空。参数名称:querySource
var memberExpression = (navigationPropertyPath.Body as MemberExpression);
var returnType = memberExpression.Member is MethodInfo? ((MethodInfo)memberExpression.Member).ReturnType: ((PropertyInfo)memberExpression.Member).PropertyType;
var parameter = Expression.Parameter(typeof(TEntity), "s");
var fieldParameter = Expression.Parameter(returnType.GetTypeInfo().GetGenericArguments()[0], "field");
var anyPredicate = Expression.Lambda(
Expression.NotEqual(
Expression.PropertyOrField(fieldParameter, "Column"),
Expression.Constant(true)
),
fieldParameter);
var fieldCondition = Expression.Call(
typeof(Enumerable).GetMethods().Where(x=>x.Name == "Any").Skip(1).Take(1).First().MakeGenericMethod(new[] { fieldParameter.Type }),
memberExpression,
anyPredicate);
// You can use the fieldCondition in your combinator,
// the following is just to complete the example
var predicate = Expression.Lambda<Func<TEntity, bool>>(fieldCondition, parameter);
var list= source.Where(predicate).ToList(); ;
此代码创建自定义标准WHERE
查询,并尝试将结果转换为列表。
有谁知道如何解决这个问题?