Intersect LINQ query

后端 未结 7 1968
北恋
北恋 2020-11-30 00:57

If I have an IEnumerable where ClassA exposes an ID property of type long. Is it possible to use a Linq query to get all instances of ClassA with ID belonging to a second IE

7条回答
  •  庸人自扰
    2020-11-30 01:40

    I've been tripping up all morning on Intersect, and how it doesn't work anymore in core 3, due to it being client side not server side.

    From a list of items pulled from a database, the user can then choose to display them in a way that requires children to attached to that original list to get more information.

    What use to work was:

    itemList = _context.Item
            .Intersect(itemList)
            .Include(i => i.Notes)
            .ToList();
    

    What seems to now work is:

    itemList = _context.Item
            .Where(item => itemList.Contains(item))
            .Include(i => i.Notes)
            .ToList();
    

    This seems to be working as expected, without any significant performance difference, and is really no more complicated than the first.

提交回复
热议问题