Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access

Category: .NET

.NET / Asp.Net Core / C#

EF Core 8 ExecuteUpdate – Batch Updates Without Loops

- 04.12.25 | 04.12.25 - ErcanOPAK

ExecuteUpdate allows batch updates without tracking overhead. await ctx.Users .Where(u => u.IsActive == false) .ExecuteUpdateAsync(p => p.SetProperty(x => x.IsDeleted, true));   It’s fast, clean, and ideal for big-data operations.

Read More
.NET / Asp.Net Core / C#

Every Async Method Should Accept CancellationToken

- 04.12.25 | 04.12.25 - ErcanOPAK

CancellationToken prevents zombie tasks and ensures graceful shutdown. public Task RunAsync(CancellationToken ct) It is a must-have for cloud-native workloads.

Read More
.NET / Asp.Net Core / C#

Lightning-Fast Lookups in .NET Using MemoryCache

- 04.12.25 | 04.12.25 - ErcanOPAK

MemoryCache provides a simple and fast in-memory caching solution. var item = cache.GetOrCreate(“users”, entry => { entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10); return repo.GetUsers(); }); Ideal for configuration, lookups, and session data.

Read More
.NET / Asp.Net Core / C#

Boost Async Performance in .NET with ConfigureAwait(false)

- 04.12.25 | 04.12.25 - ErcanOPAK

Using ConfigureAwait(false) can significantly reduce context-switching overhead in non-UI .NET applications. This is essential for APIs, background services, and any high-throughput async pipeline. await http.SendAsync(req).ConfigureAwait(false); It lowers CPU usage, avoids deadlocks, and improves overall async performance.

Read More
.NET / Asp.Net Core / C#

Clean Minimal APIs in .NET – Automatic DTO Binding Explained

- 04.12.25 | 04.12.25 - ErcanOPAK

Minimal APIs provide automatic DTO binding, eliminating unnecessary boilerplate. app.MapPost(“/login”, (LoginRequest req) => { return Results.Ok($”Welcome {req.Email}”); }); This improves readability, reduces errors, and works perfectly with endpoint filters.

Read More
.NET / Asp.Net Core / C#

Write Cleaner Business Logic Using C# Switch Expressions

- 04.12.25 | 04.12.25 - ErcanOPAK

Switch expressions simplify complex branching logic and make code more readable. var price = plan switch { “free” => 0, “pro” => 19, “biz” => 49, _ => throw new Exception(“Unknown plan”) }; They are ideal for pricing models, rules engines, and state transitions.

Read More
.NET / Asp.Net Core / C#

EF Core Performance Boost: Use AsNoTracking() When Reading Data

- 04.12.25 | 04.12.25 - ErcanOPAK

For read-heavy queries, AsNoTracking() provides massive performance improvements. var users = await ctx.Users.AsNoTracking().ToListAsync(); It avoids adding entities to the change tracker, improving speed by 30–50%.

Read More
.NET / Asp.Net Core / C#

Use IAsyncEnumerable for Streaming Data in .NET

- 04.12.25 | 04.12.25 - ErcanOPAK

IAsyncEnumerable allows true async streaming, reducing memory usage. await foreach (var user in repo.GetAllAsync()) Console.WriteLine(user.Name); Perfect for large datasets and high-throughput APIs.

Read More
.NET / Asp.Net Core / C#

Why C# Record Types Are Perfect for Modern DTOs

- 04.12.25 | 04.12.25 - ErcanOPAK

Records offer immutability, value semantics, and minimal syntax. public record UserDto(int Id, string Name, string Email); They are ideal for APIs, events, and data-transfer layers.

Read More
.NET / Asp.Net Core / C#

Improve .NET Logging with Structured Log Messages

- 04.12.25 | 04.12.25 - ErcanOPAK

Structured logs allow smarter querying and cleaner search results. logger.LogInformation(“User {UserId} logged in”, id); They improve observability, diagnostics, and production monitoring.

Read More
.NET / Asp.Net Core / C#

Never Write Retry Logic Again – Use Polly in .NET

- 04.12.25 | 04.12.25 - ErcanOPAK

Polly provides retry, timeout, fallback, and circuit-breaker patterns. var result = await Policy .Handle() .RetryAsync(3) .ExecuteAsync(() => CallApi()); It’s the gold standard for resilience in .NET microservices.

Read More
.NET

The One DI Rule You Must Not Break: Avoid Injecting Scoped into Singleton

- 04.12.25 | 04.12.25 - ErcanOPAK

Mixing Scoped services inside Singletons causes threading issues and hidden bugs. Always match lifetime scopes properly to avoid race conditions and stale state.

Read More
.NET / Asp.Net Core / C# / Entity Framework

Stop Calling ToList() Too Early – Improve LINQ Performance

- 04.12.25 | 04.12.25 - ErcanOPAK

Calling ToList() too early forces premature execution. // Bad var items = db.Users.ToList().Where(…); // Good var items = db.Users.Where(…).ToList();   Let the database handle filtering and execution.

Read More
.NET / Asp.Net Core / C#

Build Clean Background Services with IHostedService in .NET

- 04.12.25 | 04.12.25 - ErcanOPAK

BackgroundService enables clean, scalable background processing. protected override async Task ExecuteAsync(CancellationToken ct) { while (!ct.IsCancellationRequested) { await DoWork(); await Task.Delay(1000, ct); } } It works perfectly in cloud-native environments.

Read More
.NET / Asp.Net Core / C#

Cleaner .NET APIs Using IEndpointFilter for Validation

- 04.12.25 | 04.12.25 - ErcanOPAK

Endpoint filters reduce validation noise in Minimal APIs. public class ValidateFilter : IEndpointFilter { public Task<object?> InvokeAsync(EndpointFilterInvocationContext ctx, EndpointFilterDelegate next) { var model = ctx.GetArgument(0); Validator.ValidateObject(model, new()); return next(ctx); } } They keep endpoints clean, reusable, and testable.

Read More
February 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
232425262728  
« Jan    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (934)
  • How to add default value for Entity Framework migrations for DateTime and Bool (830)
  • Get the First and Last Word from a String or Sentence in SQL (822)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (708)
  • Add Constraint to SQL Table to ensure email contains @ (572)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (552)
  • Average of all values in a column that are not zero in SQL (517)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (473)
  • Find numbers with more than two decimal places in SQL (436)

Recent Posts

  • C#: Use init Accessor to Create Immutable Objects Without Constructor Boilerplate
  • C#: Use Index and Range Operators for Cleaner Array Slicing
  • C#: Use Null-Coalescing Assignment to Simplify Lazy Initialization
  • SQL: Use CHAR Instead of VARCHAR for Fixed-Length Columns to Save Space
  • SQL: Use CROSS APPLY Instead of Subqueries for Better Performance
  • .NET Core: Use Required Modifier to Force Property Initialization
  • .NET Core: Use Global Using Directives to Avoid Repeating Imports
  • Git: Use git restore to Unstage Files Without Losing Changes
  • Git: Use git bisect to Find Which Commit Introduced a Bug
  • AJAX: Use Fetch with Signal to Cancel Requests When User Navigates Away

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (934)
  • How to add default value for Entity Framework migrations for DateTime and Bool (830)
  • Get the First and Last Word from a String or Sentence in SQL (822)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (708)

Recent Posts

  • C#: Use init Accessor to Create Immutable Objects Without Constructor Boilerplate
  • C#: Use Index and Range Operators for Cleaner Array Slicing
  • C#: Use Null-Coalescing Assignment to Simplify Lazy Initialization
  • SQL: Use CHAR Instead of VARCHAR for Fixed-Length Columns to Save Space
  • SQL: Use CROSS APPLY Instead of Subqueries for Better Performance

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com