tags / EF Core

Entity Framework Core Articles

How to Execute Code Before Every Request

Need to run logic for every incoming HTTP request?

Use ASP.NET Core middleware.

Common middleware scenarios:

  • Logging requests
  • Handling exceptions
  • Authentication
  • Authorization
  • Adding custom headers
  • Response compression

Middleware executes in the order you register it in the pipeline.

Each middleware can inspect the request, perform work, and pass execution to the next middleware.

How middleware works in .NET

How to Use SaveChangesAsync in .NET

Want asynchronous database writes in EF Core?

Use SaveChangesAsync() instead of SaveChanges().

How to Use SaveChangesAsync in .NET

Benefits:

  • Doesn't block the calling thread
  • Works better under load
  • Integrates with async/await
  • Recommended for ASP.NET Core applications
  • Available since EF Core was released

What other EF Core performance tips do you use?