Coming in Entity Framework 9: Better Query Parameterization

Hallelujah. With current versions of Entity Framework, when developers add a mix of parameters and specific values to their query like this:

async Task<List<Post>> GetPosts(int id) => await context.Posts .Where( e => e.Title == « .NET Blog » && e.Id == id) .ToListAsync();

See how part of the filter is hard-coded (“.NET Blog”) while the other part of the filter is dynamically generated, an ID the user is looking for? That causes Entity Framework to generate a query that is partially parameterized:

info: 2/5/2024 15:43:13.789 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command) Executed DbCommand (1ms) [Parameters=[@__id_0=’1′], CommandType=’Text’, CommandTimeout=’30’] SELECT [p].[Id], [p].[Archived], [p].[AuthorId], [p].[BlogId], [p].[Content], [p].[Discriminator], [p].[PublishedOn], [p].[Title], [p].[PromoText], [p].[Metadata]