Jan 19 2026
var employeeList = context.Employees .Select(e => new EmployeeDto { Name = e.Name, Email = e.Email }) .ToList();
// Retrieve all blogs - 1 query var blogs = context.Blogs.ToList(); foreach (var blog in blogs) { // For each blog, this will trigger an additional query // to fetch its posts - N queries var posts = blog.Posts; foreach (var post in posts) { Console.WriteLine(post.Title); } }
// Retrieve all blogs and their posts in a single query using eager loading var blogs = context.Blogs.Include(b => b.Posts).ToList(); foreach (var blog in blogs) { foreach (var post in blog.Posts) { Console.WriteLine(post.Title); } }
var products = context.Products.AsNoTracking().ToList(); // Use products for read-only purposes
// Incorrect query leading to cartesian explosion var query = from a in context.Authors from b in context.Books select new { a.Name, b.Title }; var results = query.ToList(); // This will produce a cartesian product
// Correct query using a proper join var query = from a in context.Authors join b in context.Books on a.AuthorId equals b.AuthorId select new { a.Name, b.Title }; var results = query.ToList(); // This produces the correct result
var authors = context.Authors .Include(a => a.Books) .ToList();
var authors = context.Authors .Include(a => a.Books) .AsSplitQuery() .ToList();
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.