Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
LINQ Aggregation Operators: Count, Sum, Average, Min, Max, Aggregate and MinBy/MaxBy
Why Sum returns 0 and Max throws on an empty sequence, and the nullable selector and DefaultIfEmpty fixes. Count and .NET 6 TryGetNonEnumeratedCount, the return type of Average, the checked overflow of Sum, MinBy/MaxBy returning the element instead of the value, the three overloads of Aggregate, and how many times you enumerate the same query.
LINQ Partitioning: Take, Skip, TakeWhile, Chunk and Take(Range)
Why TakeWhile is not a filter, correct paging with Skip and Take and the silent rule of ordering, how TakeLast/SkipLast read to the end, Take(Range) from .NET 6 versus array slicing, splitting into batches with Chunk, and exactly how much of the source the partitioning operators read.
LINQ Element Operators: First, Last, Single, ElementAt and OrDefault
The First, Last, Single and ElementAt families and their OrDefault siblings; how 0 gets confused with 'not found' on value types, .NET 6's default value parameter and Index overloads, the difference in intent between First and Single, and nullable warnings.
Projection with LINQ: Select, SelectMany and Anonymous Types
One-to-one projection with Select and one-to-many with SelectMany; mapping to DTOs, keeping parent data with a result selector, the Cartesian product, the equality and with rules of anonymous types, and tuple versus record outside a method.
Filtering and Sorting with LINQ: Where, OrderBy, ThenBy and Reverse
Where and its index overload, why a second OrderBy wipes out the first, multi-key sorting with ThenBy, stable OrderBy versus unstable List.Sort, culture-sensitive string ordering, and how Reverse differs from OrderByDescending.
LINQ Deferred Execution: When Does a Query Run? IEnumerable and IQueryable
Why a LINQ query runs when it is iterated rather than when it is defined, element-by-element streaming, immediate and buffering operators, the cost of multiple enumeration, and the IEnumerable versus IQueryable split through Func and expression trees.
What Is LINQ? Query Syntax and Method Syntax in C#
What LINQ changes about the queries we used to write with loops, the C# 3.0 features behind it, how the compiler translates query syntax into method calls, when to pick which notation, and the first pitfalls.
LINQ Queries with EF Core: SQL Translation, Client Evaluation and the IQueryable Trap
We follow how an EF Core LINQ query becomes SQL: deferred execution, ToQueryString and LogTo, filtering, sorting and paging, projection, First/Single/Find, client evaluation allowed in the final Select, and the IEnumerable trap that silently pulls the whole table.