使用 ODataQueryOptions 过滤包含自定义类型的 Linq

Filtering on Linq that contains Custom Type using ODataQueryOptions

在执行服务器端操作的 MVC 中实现 Kendo 网格时,我发现自己处于一个棘手的境地,即我必须使用 linq 过滤、排序、分页我的数据。我得到的所有信息都是 ODataQueryOptions 类型。

(不确定是否有必要提及,但为了完整起见,我们通过UnitOfWork模式进行查询操作)

所以执行查询的操作复制如下:

public static List<T> GetT(this IRepositoryAsync<T> repository, ODataQueryOptions<T> options)
    {
        var query = repository.Query().Tracking(false).Include(x => x.T2)
            .Select(s => new
            {
                P1 = s.P1,
                P2 = s.P2,
                P3 = s.T2.P1 + "," + s.T2.P2
            })
            .Select(s => new T1
            {
                P1 = s.P1,
                P2 = s.P2,
                P3 = s.P3
            });

        if (options.Skip != null)
            query = query.Skip(options.Skip.Value);
        if (options.Top != null)
            query = query.Take(options.Top.Value);

        return query.ToList();
    }

现在,我想知道是否可以选择将剩余的 oData 选项应用于 linq 查询(如您所见,$skip 和 $top 已应用,我们如何应用 OrderByQueryOption 和 FilterQueryOption)。

OrderByQueryOption there is a property OrderByNodes you can use this to construct your query, but in FilterQueryOption, it's hard to translate the FilterClause, you need the FilterBinder to do this for you but it's not public in 5.9.1, it's public in 6.0.0.