LINQ:字段不是引用字段
我有一个 IQueryable 列表。我试图将此列表拆分为第一个列表中某个字段(例如 fieldnum)匹配的 IQueryable 数组...
例如,如果 fieldnum == 1,它应该进入 array[1]。我正在使用Where()基于此字段进行过滤,它看起来像这样:
var allItems = FillListofMyObjects();
var Filtered = new List<IQueryable<myObject>(MAX+1);
for (var i = 1; i <= MAX; i++)
{
var sublist = allItems.Where(e => e.fieldnum == i);
if (sublist.Count() == 0) continue;
Filtered[i] = sublist;
}
但是,我在if行上收到错误Field“t1.fieldnum”不是参考字段 。单步执行调试器显示错误实际上发生在之前的行(Where() 方法)上,但无论哪种方式,我都不知道我做错了什么。
我对 LINQ 还很陌生,所以如果我做错了,请告诉我,谢谢!
I've got a list of IQueryable. I'm trying to split this list into an array of IQueryable matching on a certain field (say fieldnum) in the first list...
for example, if fieldnum == 1, it should go into array[1]. I'm using Where() to filter based on this field, it looks something like this:
var allItems = FillListofMyObjects();
var Filtered = new List<IQueryable<myObject>(MAX+1);
for (var i = 1; i <= MAX; i++)
{
var sublist = allItems.Where(e => e.fieldnum == i);
if (sublist.Count() == 0) continue;
Filtered[i] = sublist;
}
however, I'm getting the error Field "t1.fieldnum" is not a reference field on the if line. stepping through the debugger shows the error actually occurs on the line before (the Where() method) but either way, I don't know what I'm doing wrong.
I'm farily new to LINQ so if I'm doing this all wrong please let me know, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接使用 ToLookup ?
每次获得值时都需要重新计算表达式吗?
Why don't you just use ToLookup?
Do you need to reevaluate the expression every time you get the values?
为什么不使用字典呢?
Why not use a dictionary?