I am not using Single
in LINQ below, but I am still getting a 'Sequence contains no elements' exception:
allNames = StockCollection.Where((s) => s.Name.IndexOf("A") == 0)
.Select((s) => s.Name)
.Aggregate((namesInfo, name) => namesInfo += ", " + name);
This exception comes when there is no stock starting with name 'A'
.
It seems that one extension method is expecting atleast one element satisfying the condition but that's not expected.
Can you please suggest the best solution to resolve this?
Thanks in advance.