So sometimes you will get these strange errors or exceptions when using Linq Sequence contains no matching element
For example if you use
This will throw InvalidOperationException with Sequence contains no matching element.
But if you use
Which will return you a null if its not found then you can check if the result is null and continue on with your work
Hope this helps
thanks this helped!
Thanks very much, I started using it.
Thank you! Exactly what i want!
Didn’t work for me. I think my error was caused because my ICollection had no items.
Turns Out First throws an exception if a list element can’t be found. MS Suggests using SingleOrDefault instead which will return null if no matching element is found.
Thanks for this help