dotnet / dotnet/efcore

Precompiled Queries fail for captured parameters

Open
#35,887 13 comments 4 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-aot area-precompiled-queries customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### Type of issue

Code doesn't work

### Description

Hello.

I tried to use precompiled queries in EF9 by following the instructions in this page. However, it always end up with:

```
D:\packages\NuGet\cache\microsoft.entityframeworkcore.tasks\9.0.3\buildTransitive\Microsoft.EntityFrameworkCore.Tasks.targets(93,5): error : Query precompilation failed with errors:
D:\packages\NuGet\cache\microsoft.entityframeworkcore.tasks\9.0.3\buildTransitive\Microsoft.EntityFrameworkCore.Tasks.targets(93,5): error : QueryPrecompilationError { SyntaxNode = context.Todos.OrderBy(b => b.Id).AsAsyncEnumerable(), Exception = System.InvalidOperationException: Dynamic LINQ queries are not supported when precompiling queries. }
D:\packages\NuGet\cache\microsoft.entityframeworkcore.tasks\9.0.3\buildTransitive\Microsoft.EntityFrameworkCore.Tasks.targets(93,5): error :
```
when I run `dotnet publish -r win-x64 -o publish`

Here is my minimal repro:
https://github.com/vancodocton/NativeAot/tree/9813f8ec755f6149bc9209a54b288e44d2f89f5f

### Page URL

https://learn.microsoft.com/en-us/ef/core/performance/nativeaot-and-precompiled-queries

### Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/performance/nativeaot-and-precompiled-queries.md

### Document Version Independent Id

d0be1f4d-9f8a-2547-ce96-8ed38a4be225

### Platform Id

134032fb-f272-255a-1b6a-4858e71e1c88

### Article author

@roji

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.