#LINQ-Queries
Writing complex LINQ queries using natural language is a wonderful way to learn and get things done while debugging.

Coming soon to Visual Studio...
November 27, 2024 at 5:14 PM
SQLProvider has added separate database-specific NuGet packages. This way, the users can forget the initial setup struggles with the resolutionPath dlls. github.com/fsprojects/S...
GitHub - fsprojects/SQLProvider: A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides. - fsprojects/SQLProvider
github.com
May 8, 2025 at 1:58 PM
Haskell directly inspired the C# designers when they implemented LINQ 😉
stackoverflow.com/a/4683716
Are there any connections between Haskell and LINQ?
I wrote some queries in C# using LINQ. After a while, I started using Haskell a little bit, which is a functional programming language (a not so popular one), and for me it seems that both of them ...
stackoverflow.com
January 27, 2026 at 2:24 PM
Entity Framework Core Pitfalls: Calling DB Functions in LINQ Queries as Extension Methods from @rjperes.bsky.social
#dotnet #efcore

developmentwithadot.blogspot.com/2025/02/enti...
Entity Framework Core Pitfalls: Calling DB Functions in LINQ Queries as Extension Methods
Calling DB Functions in EF Core LINQ Queries
developmentwithadot.blogspot.com
February 10, 2025 at 4:01 PM
Explore the power of Dynamic LINQ and C# Eval Expressions to streamline queries and boost code efficiency. Learn how to harness these features for flexible data manipulation! #CSharp #Programming
Exploring Dynamic LINQ and C# Eval Expression - Coding Sonata
Learn about the 2 powerful libraries for dynamic processing of LINQ queries and C# code at runtime. Dynamic LINQ and C# Eval Expression.
codingsonata.com
December 16, 2025 at 9:15 PM
oh i don't use linq for database queries, just the wonderful suite of ienumerable extensions
March 6, 2025 at 10:12 PM
The N+1 Query Problem: Why Your LINQ Query Makes 1001 Database Calls
# The N+1 Query Problem: Why Your LINQ Query Makes 1001 Database Calls Your query returns 1000 orders. Your database log shows 1001 queries. One to fetch the orders, then one for each order's customer. This is the N+1 problem — and it's probably happening in your codebase right now. ## The Innocent-Looking Code var orders = dbContext.Orders.ToList(); foreach (var order in orders) { Console.WriteLine($"Order {order.Id} by {order.Customer.Name}"); } What you expect: one query fetching orders with customer names. What happens: 1. `SELECT * FROM Orders` — fetches 1000 orders 2. `SELECT * FROM Customers WHERE Id = 1` — for order 1 3. `SELECT * FROM Customers WHERE Id = 2` — for order 2 4. ... 998 more queries ... If each query takes 5ms, you've turned a 10ms operation into a 5-second disaster. ## Why It Happens Entity Framework uses lazy loading by default (or used to — EF Core made it opt-in). When you access `order.Customer`, EF sees the navigation property isn't loaded and fires a query. The insidious part: it works perfectly in development with 10 records. In production with 10,000? Your API times out. ## The Solution: Eager Loading with Include var orders = dbContext.Orders .Include(o => o.Customer) // Load customers with orders .ToList(); foreach (var order in orders) { Console.WriteLine($"Order {order.Id} by {order.Customer.Name}"); } Now EF generates one query with a JOIN. Customer data comes with the order in a single round-trip. ## Nested Includes For deeper relationships: var orders = dbContext.Orders .Include(o => o.Customer) .Include(o => o.OrderItems) .ThenInclude(oi => oi.Product) // Nested: OrderItem's Product .ToList(); `ThenInclude` continues from the last included collection. You can chain them for complex graphs. ## The Projection Alternative `Include` loads entire entities. Often, you don't need all columns: // Instead of Include... var orders = dbContext.Orders .Include(o => o.Customer) .Include(o => o.OrderItems) .ToList(); // ...project to what you actually need var orders = dbContext.Orders .Select(o => new { o.Id, CustomerName = o.Customer.Name, ItemCount = o.OrderItems.Count, Total = o.OrderItems.Sum(oi => oi.Price) }) .ToList(); The projection approach generates one query that fetches exactly the columns needed. No N+1, minimal data transfer. Fun fact: The term "N+1" comes from the mathematical pattern: 1 query for the parent collection, plus N queries for each child. It was popularized by the Ruby on Rails community around 2006, but the problem existed anywhere ORMs did automatic lazy loading. The ActiveRecord pattern (from Martin Fowler's 2002 book) made it endemic. ## AsSplitQuery: When Include Gets Too Wide Wide includes (many navigation properties or deep nesting) produce massive JOINs. EF Core 5+ offers split queries: var orders = dbContext.Orders .Include(o => o.OrderItems) .Include(o => o.ShippingAddress) .Include(o => o.BillingAddress) .AsSplitQuery() // Separate queries instead of mega-JOIN .ToList(); `AsSplitQuery` fires multiple simple queries instead of one giant JOIN. For complex includes with many columns, split queries can actually be faster. Trade-off: multiple round-trips vs one huge result set. Profile to decide. ## Detecting N+1 in the Wild ### Option 1: EF Core Logging optionsBuilder.LogTo(Console.WriteLine, LogLevel.Information); Watch the output. Multiple SELECT statements for navigation properties = N+1. ### Option 2: Simple Query Count int queryCount = 0; optionsBuilder.LogTo(msg => { if (msg.Contains("Executing DbCommand")) queryCount++; }, LogLevel.Information); If `queryCount` >> 1 for what should be one query, investigate. ### Option 3: Third-Party Tools MiniProfiler, Glimpse, or similar tools visualize queries per request. N+1 shows as a fan of identical query patterns. ## Common N+1 Patterns ### The Loop Print // Bad foreach (var order in dbContext.Orders) Console.WriteLine(order.Customer.Name); // N queries // Good foreach (var order in dbContext.Orders.Include(o => o.Customer)) Console.WriteLine(order.Customer.Name); // 1 query ### The Innocent Serialize // Bad — serializer triggers lazy loading return Json(dbContext.Orders.ToList()); // Triggers N+1 during serialization // Good return Json(dbContext.Orders .Select(o => new { o.Id, CustomerName = o.Customer.Name }) .ToList()); ### The Collection Count // Bad var orders = dbContext.Orders.ToList(); var withItems = orders.Where(o => o.OrderItems.Any()); // N queries // Good var orders = dbContext.Orders.Include(o => o.OrderItems).ToList(); var withItems = orders.Where(o => o.OrderItems.Any()); // 0 additional queries ## The Rule 1. **Accessing navigation in loops?** `Include` before iterating 2. **Don't need full entities?** Project to DTOs (avoids N+1 _and_ fetches less data) 3. **Wide includes?** Consider `AsSplitQuery` 4. **Serialize entities?** Project to anonymous/DTO first 5. **Always profile** — EF logging reveals the real query count Next time, we'll look at async LINQ — when to use `ToListAsync`, why you can't make LINQ operators truly async, and the Task patterns that work with database queries. Hope to see you!
dev.to
September 25, 2026 at 5:46 AM
🚨 Struggling with complex data queries in C#?
Master advanced LINQ operators (GroupBy, SelectMany, Join, Zip, etc.) with practical .NET examples. Write cleaner, more powerful code! 📊
Guide: www.ottorinobruni.com/advanced-lin...
Favorite LINQ operator? 👇
#dotnet #CSharp #LINQ
Advanced LINQ Operators in C# – Practical Examples for .NET Developers - Ottorino Bruni
Learn advanced LINQ operators in C# with practical examples. Explore GroupBy, SelectMany, Join, Distinct, and aggregation using a simple .NET console app.
www.ottorinobruni.com
June 3, 2026 at 1:22 PM
Oof, yeah that's nasty. Very cool work as a result, though. I've always been a fan of absurd LINQ queries.
February 8, 2026 at 4:16 PM
Tired of complex, error-prone SQL? 😩

Supercharge your data access with Linqmeup.com and write safe, powerful database queries using familiar .NET LINQ.

Get annual sub for only €48 and save €7 instantly!

Code: BLACKFR25

#BlackFriday #SQL #dotnet #developer
November 14, 2025 at 5:59 AM
Tired of slow GroupBy queries in EF Core?

With LINQ GroupBy, EF Core 6+ now translates more groupings directly into SQL. No more pulling all the data into memory—just fast, efficient queries.

woodruff.dev/grouping-sma...

#EFCore #dotnet #LINQ #DevTips #DatabasePerformance
Grouping Smarter: LINQ GroupBy Enhancements in EF Core - Chris Woody Woodruff
Grouping data in Entity Framework Core (EF Core) used to feel a little… clunky. Sometimes, LINQ’s GroupBy() worked beautifully in-memory but got lost in translation when executing SQL queries. You’d w...
woodruff.dev
February 12, 2025 at 11:37 AM
Finished a C# code review where linq queries had “internal” to/as array/list conversions. I prefer to not do that as the list/array gets discarded before the query completes, which seems wasteful
November 27, 2024 at 7:59 PM
Pro Tip: Don't use LINQ queries, like... ever
June 11, 2026 at 8:49 AM
Visualizing LINQ Queries with LINQPad: Boost Your EF Core Debugging

buff.ly/Yl6jL8Z

#dotnet #csharp #linq #efcore #linqpad
Visualizing LINQ Queries with LINQPad: Boost Your EF Core Debugging
Debug EF Core queries with ease using LINQPad. Visualize LINQ, explore data, and see generated SQL instantly for faster troubleshooting.
buff.ly
September 2, 2025 at 7:01 PM
Sure, that sounds great. One of my original goals was to bring LINQ-style queries to TypeScript using real, type-checked code instead of a DSL. I’ve been a fan of some of the C# syntax patterns
June 15, 2025 at 7:22 PM
Distinguishing between IEnumerable & IQueryable is crucial for optimizing LINQ queries. Use IEnumerable for in-memory collections & IQueryable for remote data sources to enhance performance. #dotnet #LINQ
Attention Required! | Cloudflare
medium.com
August 8, 2026 at 6:15 PM
Master LINQ in C# with these 8 essential queries! Optimize your #dotnet code and elevate your skills with practical examples. #CSharpDev
Master LINQ in C# with These 8 Queries
Hi, my name is Saif, and today I want to share something every C# developer should have in their toolkit — LINQ.
medium.com
August 9, 2025 at 12:15 AM
🔍 LINQ in C# – Practical Guide for .NET Developers Replace messy foreach loops with clean, declarative queries. Filter, project, group, join – readable & powerful code. #dotnet #csharp #linq #dotnetdev #programming www.ottorinobruni.com/how-to-use-l...
How to Use LINQ in C# – Practical Examples for .NET Developers - Ottorino Bruni
Learn how to use LINQ in C# with practical, real-world examples. Understand Where, Select, OrderBy, FirstOrDefault and how to write clean, readable queries in .NET
www.ottorinobruni.com
March 4, 2026 at 9:43 AM
Optimize your LINQ queries in C#! Discover 5 key patterns to enhance performance, from Lazy Evaluation to Effective Use of AsParallel. Boost your code efficiency today. #CSharp #LINQ
Just a moment...
towardsdev.com
June 4, 2026 at 9:15 PM
🚀Dive into the performance trade-offs of LINQ vs foreach() loops in collection queries! Benchmark results reveal surprising insights—foreach() outperforms LINQ by 1.75x. Check out the findings and optimize your code! Read more.
#dotnet8 #MVPBuzz #dotnet
Collection Performance: Is LINQ Always the Most Performant Choice?
The article explores the performance implications of using LINQ for collection queries, finding that a conventional foreach() loop outperforms LINQ by 1.75 times in identifying items matching a giv…
dotnettips.wordpress.com
January 27, 2025 at 2:39 PM
Enhanced Editable Expression in IEnumerable Visualizer! | www.youtube.com/watch?v=nzbJ... by the Microsoft Visual Studio team
Enhanced Editable Expression in IEnumerable Visualizer!
🚀 Enhanced Editable Expression in IEnumerable Visualizer! Now with inline Copilot chat, effortlessly generate and refine LINQ queries to filter your data. N...
www.youtube.com
March 25, 2025 at 2:38 PM
Are you a .NET developer that’s migrating a project with dreaded hard coded SQL queries 😱??

No worries, convert your SQL into debuggable LINQ code easily, using

LINQ Me Up:

🔗: www.linqmeup.com

#dotnet #sql #developer
LINQ Me Up - Boost your .Net productivity with AI-powered LINQ generation & conversion
LINQ Me Up helps you save time by converting SQL into LINQ or LINQ into SQL and generating LINQ from your dataset input. Supports C# and Visual Basic code and Method and Query syntax.
www.linqmeup.com
July 2, 2025 at 9:37 AM