From “Fixing LINQ Error: Sequence contains no elements”:
When you get the LINQ error “Sequence contains no elements”, this is usually because you are using the
First()orSingle()command rather thanFirstOrDefault()andSingleOrDefault().
This can also be caused by the following commands:
FirstAsync()SingleAsync()Last()LastAsync()Max()Min()Average()Aggregate()