Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How do I use ElementAt in LINQtoSQL, C#?

I haven't found a way of using this successfully to extract an object from an IQueryable list selected from a table. Any ideas?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    I tried this and could not get it to work either. I did a little searching a found a few sites that seem to indicate that you can't use ElementAt on an IQueryable in Linq to SQL. I am thinking that the reason for this is that Linq to SQL will attempt to turn an IQueryable into the equivalent SQL statement, but there is no equivalent to "ElementAt" in SQL. You can get around it by using AsEnumerable<T> before ElementAt like this:

    Issue i = Issues.Where(c => c.ProjectID == projectID).AsEnumerable<Issue>().ElementAt<Issue>(0);

  • 1 decade ago

    you just stopped my little red wagon.maybe someone else can answer that,sorry.

Still have questions? Get your answers by asking now.