不幸的是,SQL Server无法处理超过2100个参数的参数列表。我有几个查询,当在批处理模式下运行超过此限制。为了获得我想要的结果并快速循环访问数据集,我决定在for循环中使用Skip(i).Take(2000)
。为什么我不能Concat或联盟的结果到一个空的列表?
我没有准备的是Union
和Concat
要求IEnumerable
不仅仅是实例化的工作。确定它是空的,但我必须错过关于它们的使用的一些基本信息。无论如何,为了解决这个问题,我最终使用了一个List和AddRange
。我正在使用NHibernate,但不要认为,为什么Union
和Concat
不起作用的因素。
var machineResults = new List<Machine>();
for (int i = 0; i < machines.Count(); i += 2000)
{
// I would have expected Union or Concat to work here
machineResults.AddRange(GetSession().CreateQuery(
@"select distinct m
from Machine m
where m in (:MachinesList)") // there's more criteria than this
.SetParameterList("MachinesList",
machines.Skip(i).Take(2000).ToList())
.List<Machine>());
}
return machineResults;
所以我缺少什么关于Union
和Concat
?他们为什么不在上述陈述中工作?我明白为什么AddRange能够工作,但是如果我担心我的结果的独特性并想使用Union
?
Doh!感谢慢跑我的记忆。很晚了,我要去睡觉了。 – ahsteele 2012-02-17 06:50:21