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

后端 未结 2 1320
执念已碎
执念已碎 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<Line>. 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);
    
    0 讨论(0)
  • 2021-01-21 23:53

    Alright. All I needed to do is to implement IEqualityComparer<T> in Line class.

    0 讨论(0)
提交回复
热议问题