我最近开始使用 Telerik 网格(用于 ASP.NET MVC)。 “基于 Linq 的表达式引擎”为您完成所有繁重的工作:分页、排序和过滤。它只需要与这样的存储库方法连接:
public IEnumerable GetBlas()
{
返回Session.Query();
。
我现在有以下问题 我想使用 ICriteria 和 Restrictions.In("x", list.ToArray()) ,其中 list 的类型为 IList 并由另一个进程填充。问题是列表可以包含数百个值,这可能会引发异常,因为生成的 SQL 代码的“IN PART”(例如 IN (1, 2, ....., 10000))可能太长。
有没有一种方法可以实现这一点,而不必切换到纯 SQL 并处理 Telerik 网格发送的所有查询字符串等?希望这是有道理的。
谢谢。
基督教
I have started to use telerik grids recently (for ASP.NET MVC). The 'Linq-based expression engine' does all the heavy lifting for you: paging, sorting and filtering. It just needs to be hooked up with a repository method like this:
public IEnumerable GetBlas()
{
return Session.Query();
}
I have the following problem now. I would like to use ICriteria and Restrictions.In("x", list.ToArray()) where list is of type IList and is populated by another process. The problem is that list can contain hundreds of values and this might throw an exception as the generated SQL code’s ‘IN PART’ (e.g. IN (1, 2, ....., 10000)) might be far too long.
Is there a way to implement this without having to switch to pure SQL and dealing with all the query strings etc. the telerik grid sends? Hope this makes sense.
Thanks.
Christian
发布评论
评论(1)
这个想法是将 10,000 个项目的列表分成较小的列表,每个列表(例如)1000 个项目。
执行查询的最简单方法是使用
ICriteria
,您可以根据需要为每个子集合添加任意数量的Disjunction
。如果
ICriteria
不是一个选项,可以有一个解决方法,您可以创建多个Future
查询,如下所示(经过测试的代码,仅与数据库进行 1 次往返):The idea is to divide the list of 10,000 items into smaller lists of (say) 1000 items each.
The easiest way to do the query is using
ICriteria
, where you can add as manyDisjunction
s as you need for each sub-collection you have.If
ICriteria
is not an option, there can be a workaround where you create multipleFuture
queries, like so (tested code, which does only 1 roundtrip to the db):