September 16 2024
public void QueryInsideLoop() { using var context = new MyDbContext(); for (int i = 1; i <= 100; i++) { var entity = context.MyEntities.FirstOrDefault(e => e.Id == i); } }
public void QueryOutsideLoop() { using var context = new MyDbContext(); var entities = context.MyEntities .Where(e => e.Id <= 100) .ToList(); foreach (var entity in entities) { var id = entity.Id; // Simulating loop logic } }

public void SelectAllColumns() { using var context = new MyDbContext(); var results = context.MyEntities.ToList(); }
public void SelectImportantColumns() { using var context = new MyDbContext(); var results = context.MyEntities.Select(e => new { e.Id, e.Name }).ToList(); }

public void SelectWithTracking() { using var context = new MyDbContext(); var results = context.MyEntities.ToList(); }
public void SelectWithNoTracking() { using var context = new MyDbContext(); var results = context.MyEntities.AsNoTracking().ToList(); }
![]()
public void DefaultSingleQuery() { using var context = new MyDbContext(); var results = context.MyEntities .Include(e => e.RelatedEntities) .ToList(); }
public void UsingSplitQuery() { using var context = new MyDbContext(); var results = context.MyEntities .Include(e => e.RelatedEntities) .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.