Mid EF Core

How to use compiled queries for performance?

  • Precompile frequently used queries to improve performance:

private static readonly Func<MyDbContext, int, Product>

_getProductById =

EF.CompileQuery((MyDbContext ctx, int id) =>

ctx.Products.First(p => p.Id == id));

// Usage:

var product = _getProductById(context, 5);

More from Entity Framework Core Tutorial

All questions for this course