Posts about LINQ

Don't return IEnumerable from action methods

December 13th 2024 ASP.NET Core LINQ

I already wrote about the potential dangers of using the IEnumerable interface in the past. But I recently encountered a bug related to it which I found worth sharing. It caused the exception filter in ASP.NET Core to not handle the exception thrown in the action method.

Beware of LINQ deferred execution

December 16th 2022 LINQ

Normally, you do not have to worry about deferred (or lazy) execution of LINQ operators. Everything works as expected, often even with better performance. However, you should be aware of it, because in some cases the code does not behave as expected because of it.

Deferred Evaluation of Collections Passed as Parameters

May 26th 2014 Validation LINQ

Having a parameter of type List is not recommended; IList or even IEnumerable should be used instead when a parameter is only going to be used for iterating through the list of items. This way different types of collections, such as arrays, lists, etc. can be passed to it. But IEnumerable can prove even more useful in certain scenarios.