Share via


LINQ - Sequence contains no elements

Today I got an exception saying "Sequence contains no elements " when using LINQ against Windows Azure tables. I did a quick search and found that it is due to that I used First<> instead of FirstOrDefault<> in my code. The below link explains the issue.

https://blog.dreamlabsolutions.com/post/2008/10/28/LINQ-Sequence-contains-no-elements.aspx

btw, I expected that First<> returns null instead of throwing exception.

Comments

  • Anonymous
    April 27, 2011
    The comment has been removed
  • Anonymous
    April 27, 2011
    Good point. Thanks Keith. I expected it returned null instead of throwing exception.