我建立一个ASP.Net MVC 3应用程序与实体框架4.当两段代码如下执行,这两个变量(QUERY1和QUERY2)有LINQ动态查询库
System.Data.Objects.ObjectQuery<Asset.Model.Equipment>
返回类型
Query1使用ObjectContext的直接实例,但是,Query2使用一个存储库模式,即它在EquipmentService中调用GetEquipment,它依次调用Equipment Repository中相同的命名方法。无论是在服务和库回归方法
IQueryable<Equipment>
如何,这里是我的问题,怎么来QUERY2只会在工作的时候包括
using System.Linq.Dynamic;
在我的控制器顶部
using (AssetEntities context = new AssetEntities())
{
var query1 = context.Equipments
.OrderBy("it." + sidx + " " + sord)
.Skip(pageIndex * pageSize)
.Take(pageSize);
}
var query2 = equipService.GetEquipment()
.OrderBy(sidx + " " + sord)
.Skip(pageIndex * pageSize)
.Take(pageSize);
如果我从我的控制器omitt System.Linq.Dynamic,我得到内QUERY2错误在
.OrderBy(sidx + " " + sord)
其中规定
The type arguments for method 'System.Linq.Queryable.OrderBy<TSource,TKey>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,TKey>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
有谁知道为什么QUERY1可以不必使用System.Linq.Dynamic工作,但需要QUERY2它来执行?
谢谢大家。
这是一个很好的答案。感谢您的时间:) – tgriffiths 2011-03-02 10:18:11
@tgriffiths:在[答案](http://stackoverflow.com/questions/5500805/asp-net-mvc-2-0-implementation-of-searching-in-jqgrid/5501644# 5501644)我演示了如何在jqGrid中实现过滤/搜索,它可以用于[工具栏搜索](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching)和[高级搜索] (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:advanced_searching)。我用相应的链接更新了我的答案。 – Oleg 2011-04-03 20:14:53