LINQ can throw an exception on .First() for an empty set
Pretty much what it says in the title!
If you have a resultset from your LINQ operation that contains nothing and you call .First() then you'll get an InvalidOperationException "Sequence contains no elements". Call FirstOrDefault instead, as that returns, if there's nothing well, a default.
If you have a resultset from your LINQ operation that contains nothing and you call .First() then you'll get an InvalidOperationException "Sequence contains no elements". Call FirstOrDefault instead, as that returns, if there's nothing well, a default.

Leave a comment