IQueryable .Except() is not resulting what I expect!

后端 未结 2 1321
执念已碎
执念已碎 2021-01-21 23:11

I have the following object:

Line{ String Content; Type type;}

And I have, IQeryable lines, which I perform operation

2条回答
  •  抹茶落季
    2021-01-21 23:53

    lines is IQeryable. If you do not save its result, it will run every time you select from it. If Line does not override Equals and ==, that will create different objects each time, so Except cannot remove the previous object from new objects.

    Now, a lot is missing, but try:

    var linesList = lines.ToList(); // get results ones
    var hasX = lines.Where(line => line.Content.Contains('x'));
    var noX = lines.Except(hasX);
    

提交回复
热议问题