Skip to content

Commit 7371c56

Browse files
committed
Address review comments
1 parent 13503b1 commit 7371c56

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

entity-framework/core/miscellaneous/nativeaot-and-precompiled-queries.md renamed to entity-framework/core/performance/nativeaot-and-precompiled-queries.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: NativeAOT Support and Precompiled Queries (Experimental) - EF Core
33
description: Publishing NativeAOT Entity Framework Core applications and using precompiled queries
44
author: roji
55
ms.date: 11/10/2024
6-
uid: core/miscellaneous/nativeaot-and-precompiled-queries
6+
uid: core/performance/nativeaot-and-precompiled-queries
77
---
88
# NativeAOT Support and Precompiled Queries (Experimental)
99

@@ -16,7 +16,7 @@ uid: core/miscellaneous/nativeaot-and-precompiled-queries
1616
* Small, self-contained binaries that have smaller memory footprints and are easier to deploy
1717
* Running applications in environments where just-in-time compilation isn't supported
1818

19-
EF NativeAOT applications start up much faster than the same applications without NativeAOT; aside from the general startup improvements that NativeAOT offers (i.e. no JIT compilation required on each startup), EF's NativeAOT supports removes the processing of LINQ queries and their translation to SQL; the more EF LINQ queries an application has in its code, the faster the startup gains are expected to be from NativeAOT.
19+
EF applications published with NativeAOT start up much faster than the same applications without it. In addition to the general .NET startup improvements that NativeAOT offers (i.e. no JIT compilation required each time), EF also precompiles LINQ queries when publishing your application, so that no processing is needed when starting up and the SQL is already available for immediate execution. The more EF LINQ queries an application has in its code, the faster the startup gains are expected to be.
2020

2121
## Publishing an EF NativeAOT Application
2222

@@ -38,10 +38,10 @@ C# interceptors are currently an experimental feature, and require a special opt
3838
</PropertyGroup>
3939
```
4040

41-
At this point, you're ready to precompile your LINQ queries, and generate the [compiled model](xref:core/performance/advanced-performance-topics#compiled-models) that they depend on. Make sure that you have at least version 9.0 of the EF tools (`dotnet tool list -g`), and then execute the following:
41+
Finally, the [`Microsoft.EntityFrameworkCore.Tasks`](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tasks) package contains MSBuild integration that will perform the query precompilation (and generate the required compiled model) when you publish your application:
4242

43-
```console
44-
dotnet ef dbcontext optimize --precompile-queries --nativeaot
43+
```xml
44+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="..." />
4545
```
4646

4747
You're now ready to publish your EF NativeAOT application:
@@ -50,7 +50,7 @@ You're now ready to publish your EF NativeAOT application:
5050
dotnet publish -r linux-arm64 -c Release
5151
```
5252

53-
This shows publishing a NativeAOT publishing for Linux running on ARM64; [consult this catalog](/dotnet/core/rid-catalog) to find your runtime identifier.
53+
This shows publishing a NativeAOT publishing for Linux running on ARM64; [consult this catalog](/dotnet/core/rid-catalog) to find your runtime identifier. If you'd like to generate the interceptors without publishing - for example to examine the generated sources - you can do so via the `net ef dbcontext optimize --precompile-queries --nativeaot` command.
5454

5555
Due to the way C# interceptors work, any change in the application source invalidates them and requires repeating the above process. As a result, interceptor generation and actual publishing aren't expected to happen in the inner loop, as the developer is working on code; instead, both `dotnet ef dbcontext optimize` and `dotnet publish` can be executed in a publishing/deployment workflow, in a CI/CD system.
5656

entity-framework/core/what-is-new/ef-core-9.0/whatsnew.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,17 @@ Note, however, that we plan to fully remove sync support in EF 11, so start upda
297297
## AOT and pre-compiled queries
298298

299299
> [!WARNING]
300-
> NativeAOT and query precompilation are highly experimental feature, and are not yet suited for production use. The support described below should be viewed as infrastructure towards the final feature, which will likely be released with EF 10. We encourage you to experiment with the current support and report on your experiences, but recommend against deploying EF NativeAOT applications in production.
300+
> NativeAOT and query precompilation are highly experimental features, and are not yet suited for production use. The support described below should be viewed as infrastructure towards the final feature, which will likely be released with EF 10. We encourage you to experiment with the current support and report on your experiences, but recommend against deploying EF NativeAOT applications in production.
301301
302-
EF 9.0 brings initial, experimental support for [.NET NativeAOT](/dotnet/core/deploying/native-aot), allowing the publishing of ahead-of-time compiled applications which make use of EF to access databases. To support LINQ queries in NativeAOT mode, EF reiles on _query precompilation_: this mechanism statically identifies EF LINQ queries and generates C# [_interceptors_](/dotnet/csharp/whats-new/csharp-12#interceptors), which contain code to execute each specific query. This can significantly cut down on your application's startup time, as the heavy lifting of processing and compiling your LINQ queries into SQL no longer happens every time your application starts up. Instead, each query's interceptor contains the finalized SQL for that query, as well as optimized code to materialize database results as .NET objects.
302+
EF 9.0 brings initial, experimental support for [.NET NativeAOT](/dotnet/core/deploying/native-aot), allowing the publishing of ahead-of-time compiled applications which make use of EF to access databases. To support LINQ queries in NativeAOT mode, EF relies on _query precompilation_: this mechanism statically identifies EF LINQ queries and generates C# [_interceptors_](/dotnet/csharp/whats-new/csharp-12#interceptors), which contain code to execute each specific query. This can significantly cut down on your application's startup time, as the heavy lifting of processing and compiling your LINQ queries into SQL no longer happens every time your application starts up. Instead, each query's interceptor contains the finalized SQL for that query, as well as optimized code to materialize database results as .NET objects.
303303

304304
For example, given a program with the following EF query:
305305

306306
```c#
307307
var blogs = await context.Blogs.Where(b => b.Name == "foo").ToListAsync();
308308
```
309309

310-
EF will generate a C# interceptor into your project, which will take over the query execution. Instead of processing the query and translating it to SQL every time the program starts, the interceptor has the SQL embedded right into it, allowing your program to start up much faster:
310+
EF will generate a C# interceptor into your project, which will take over the query execution. Instead of processing the query and translating it to SQL every time the program starts, the interceptor has the SQL embedded right into it (for SQL Server in this case), allowing your program to start up much faster:
311311

312312
```c#
313313
var relationalCommandTemplate = ((IRelationalCommandTemplate)(new RelationalCommand(materializerLiftableConstantContext.CommandBuilderDependencies, "SELECT [b].[Id], [b].[Name]\nFROM [Blogs] AS [b]\nWHERE [b].[Name] = N'foo'", new IRelationalParameter[] { })));
@@ -323,9 +323,9 @@ UnsafeAccessor_Blog_Name_Set(instance) = dataReader.GetString(1);
323323

324324
This uses another new .NET feature - [unsafe accessors](/dotnet/api/system.runtime.compilerservices.unsafeaccessorattribute), to inject data from the database into your object's private fields.
325325

326-
If you're interested in NativeAOT and like to experiment with cutting-edge features, give this a try! Just be aware that the feature should be consider unstable, and currently has many limitations; we expect to stabilize it and make it more suitable for production usage in EF 10.
326+
If you're interested in NativeAOT and like to experiment with cutting-edge features, give this a try! Just be aware that the feature should be considered unstable, and currently has many limitations; we expect to stabilize it and make it more suitable for production usage in EF 10.
327327

328-
See the [NativeAOT documentation page](xref:core/miscellaneous/nativeaot-and-precompiled-queries) for more details.
328+
See the [NativeAOT documentation page](xref:core/performance/nativeaot-and-precompiled-queries) for more details.
329329

330330
## LINQ and SQL translation
331331

entity-framework/toc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@
350350
href: core/performance/efficient-updating.md
351351
- name: Modeling for performance
352352
href: core/performance/modeling-for-performance.md
353+
- name: NativeAOT and precompiled queries
354+
href: core/miscellaneous/nativeaot-and-precompiled-queries.md
353355
- name: Advanced performance topics
354356
href: core/performance/advanced-performance-topics.md
355357

@@ -365,8 +367,6 @@
365367
href: core/miscellaneous/collations-and-case-sensitivity.md
366368
- name: Connection resiliency
367369
href: core/miscellaneous/connection-resiliency.md
368-
- name: NativeAOT and precompiled queries
369-
href: core/miscellaneous/nativeaot-and-precompiled-queries.md
370370
- name: Connection strings
371371
href: core/miscellaneous/connection-strings.md
372372
- name: Context pooling

0 commit comments

Comments
 (0)