类型“System.Linq.IQueryable”上不存在方法“Where”

本文关键字:不存在 Where 方法 IQueryable System Linq 类型 | 更新日期: 2023-09-27 18:33:46

我有函数做动态linq,在dbcontext上dbset哪里,但得到错误 类型System.Linq.IQueryable上不存在方法"Where"我现在没有!!

using System.Linq;
public virtual Queryable _List(string fieldNames="", string values="")
{
    _Db = Contex.Set<T>();
    var type = typeof(T);
    var property = type.GetProperty(fieldNames);
    var parameter = Expression.Parameter(type, "p");
    var propertyAccess = Expression.MakeMemberAccess(parameter, property);
    var orderByExp = Expression.Lambda(propertyAccess, parameter);
    var body2 = Expression.Call(
        typeof(Queryable),
        "Where",
        // I things this line no good but I don't now ...
        new Type[] { type, property.PropertyType },
        _Db.Expression,
        Expression.Quote(orderByExp));
    var m = _Db.Provider.CreateQuery<T>(body2);
    return m;
}

类型“System.Linq.IQueryable”上不存在方法“Where”

没有

具有两个类型参数的重载Queryable.Where。您可能正在使用此方法:

IQueryable<TSource> Where<TSource> (this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)

这意味着您应该替换以下行:

new Type[] { type, property.PropertyType },

跟:

new Type[] { type }, // this is TSource