开发者

LINQ: Field is not a reference field

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开发者_JAVA百科 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!


Why don't you just use ToLookup?

var allItemsPerFieldNum = allItems.ToLookup(e => e.fieldnum);

Do you need to reevaluate the expression every time you get the values?


Why not use a dictionary?

var dictionary = allItems.ToDictionar(y => y.fieldnum);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜