Why is the query operator 'ElementAt' is not supported in LINQ to SQL?

后端 未结 2 511
自闭症患者
自闭症患者 2020-12-31 10:03

In LINQ to SQL, I get the exception \"The query operator \'ElementAt\' is not supported.\" When trying to use the ElementAt extension method on an IQueryable return

相关标签:
2条回答
  • 2020-12-31 10:43

    It is odd, in particular because Skip() is supported. Could you, for example, do:

    var obj = source.Skip(index).First();
    

    ?

    0 讨论(0)
  • 2020-12-31 11:00

    From MSDN, Standard Query Operator Translation (LINQ to SQL) - this article contains the full list of operators that haven't been translated:

    • TakeWhile , SkipWhile
    • Reverse
    • Last , LastOrDefault
    • ElementAt , ElementAtOrDefault
    • DefaultIfEmpty

    Operators with No Translation

    The following methods are not translated by LINQ to SQL. The most common reason is the difference between unordered multisets and sequences.

    Operators

    Rationale

    ...

    ElementAt , ElementAtOrDefault

    SQL queries operate on multisets, not on indexable sequences.

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