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() or Single() command rather than FirstOrDefault() and SingleOrDefault().
This can also be caused by the following commands:
FirstAsync()
SingleAsync()
Last()
LastAsync()
Max()
Min()
Average()
Aggregate()
Please use
.FirstOrDefault()
because if in the first row of the result there is no info this instruction goes to the default info.