System.Linq.Dynamic クラスを使用してオブジェクトのリストをクエリする小さなメソッドを書いていますが、私の問題は動的名前空間にあるとは思いません。何らかの理由で GroupBy と OrderByDescending が見つかりません。私はすでに System.Linq への参照を持っています。これが最初にこれを引き起こしたと思ったものです...奇妙なことに、OrderBy と他の Linq メソッドを見つけています..私のコードは以下の通りです。
using System;
using System.Collections.Generic;
using System.Linq.Dynamic;
using System.Linq;
using System.Web;
namespace MvcTemplate.jrSite.Core
{
public static class DynamicQuery
{
public static IQueryable Query(IQueryable items, string where, string select, string groupby, string orderby, string orderbydesc, int take)
{
var ret = items;
if (where != null && where.Length != 0)
{
ret = ret.Where(where);
}
if (select != null && select.Length != 0)
{
ret = ret.Select(select);
}
if (groupby != null && groupby.Length != 0)
{
ret = ret.GroupBy(groupby);
}
if (orderby != null && orderby.Length != 0)
{
ret = ret.OrderBy(orderby);
}
if (orderbydesc != null && orderbydesc.Length != 0)
{
ret = ret.OrderByDescending(orderbydesc);
}
return ret;
}
}
}