You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: entity-framework/core/what-is-new/ef-core-9.0/whatsnew.md
+160-5Lines changed: 160 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: What's New in EF Core 9
3
3
description: Overview of new features in EF Core 9
4
4
author: ajcvickers
5
-
ms.date: 03/07/2024
5
+
ms.date: 05/02/2024
6
6
uid: core/what-is-new/ef-core-9.0/whatsnew
7
7
---
8
8
@@ -15,15 +15,113 @@ EF9 is available as [daily builds](https://github.com/dotnet/efcore/blob/main/do
15
15
> [!TIP]
16
16
> You can run and debug into the samples by [downloading the sample code from GitHub](https://github.com/dotnet/EntityFramework.Docs). Each section below links to the source code specific to that section.
17
17
18
-
EF9 targets .NET 8, and can therefore be used with either [.NET 8 (LTS)](https://dotnet.microsoft.com/download/dotnet/8.0) or a .NET 9 preview.
18
+
EF9 targets .NET 8, and can therefore be used with either [.NET 8 (LTS)](https://dotnet.microsoft.com/download/dotnet/8.0) or a [.NET 9 preview](https://dotnet.microsoft.com/download/dotnet/9.0).
19
19
20
20
> [!TIP]
21
21
> The _What's New_ docs are updated for each preview. All the samples are set up to use the [EF9 daily builds](https://github.com/dotnet/efcore/blob/main/docs/DailyBuilds.md), which usually have several additional weeks of completed work compared to the latest preview. We strongly encourage use of the daily builds when testing new features so that you're not doing your testing against stale bits.
22
22
23
+
<aname="cosmos"></a>
24
+
25
+
## Azure Cosmos DB for NoSQL
26
+
27
+
We are working on significant updates in EF9 to the EF Core database provider for Azure Cosmos DB for NoSQL.
28
+
29
+
### Role-based access
30
+
31
+
Azure Cosmos DB for NoSQL includes a [built-in role-based access control (RBAC) system](/azure/cosmos-db/role-based-access-control). This is now supported by EF9 for both management and use of containers. No changes are required to application code. See [Issue #32197](https://github.com/dotnet/efcore/issues/32197) for more information.
32
+
33
+
### Synchronous access blocked by default
34
+
35
+
> [!TIP]
36
+
> The code shown here comes from [CosmosSyncApisSample.cs](https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/Miscellaneous/NewInEFCore9.Cosmos/CosmosSyncApisSample.cs).
37
+
38
+
Azure Cosmos DB for NoSQL does not support synchronous (blocking) access from application code. Previously, EF masked this by default by blocking for you on async calls. However, this both encourages sync use, which is bad practice, and [may cause deadlocks](https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html). Therefore, starting with EF9, an exception is thrown when synchronous access is attempted. For example:
39
+
40
+
```output
41
+
System.InvalidOperationException: An error was generated for warning 'Microsoft.EntityFrameworkCore.Database.SyncNotSupported':
42
+
Azure Cosmos DB does not support synchronous I/O. Make sure to use and correctly await only async methods when using
43
+
Entity Framework Core to access Azure Cosmos DB. See https://aka.ms/ef-cosmos-nosync for more information.
44
+
This exception can be suppressed or logged by passing event ID 'CosmosEventId.SyncNotSupported' to the 'ConfigureWarnings'
45
+
method in 'DbContext.OnConfiguring' or 'AddDbContext'.
46
+
at Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, Exception exception)
47
+
at Microsoft.EntityFrameworkCore.Cosmos.Diagnostics.Internal.CosmosLoggerExtensions.SyncNotSupported(IDiagnosticsLogger`1 diagnostics)
48
+
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.DeleteDatabase()
49
+
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseCreator.EnsureDeleted()
50
+
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureDeleted()
51
+
```
52
+
53
+
As the exception says, sync access can still be used for now by configuring the warning level appropriately. For example, in `OnConfiguring` on your `DbContext` type:
Note, however, that we plan to fully remove sync support in EF11, so start updating to use async methods like `ToListAsync` and `SaveChangesAsync` as soon as possible!
61
+
62
+
### Enhanced primitive collections
63
+
64
+
> [!TIP]
65
+
> The code shown here comes from [CosmosPrimitiveTypesSample.cs](https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/Miscellaneous/NewInEFCore9.Cosmos/CosmosPrimitiveTypesSample.cs).
66
+
67
+
The Cosmos DB provider has supported primitive collections in a limited form since EF Core 6. This is support is being enhanced in EF9, starting with consolidation of the metadata and API surfaces for primitive collections in document databases to align with primitive collections in relational databases. This means that primitive collections can now be explicitly mapped using the model building API, allowing for facets of the element type to be configured. For example, to map a list of required (i.e. non-null) strings:
See [What's new in EF8: primitive collections](xref:core/what-is-new/ef-core-8.0/whatsnew#primitive-collections) for more information on the model building API.
77
+
78
+
## AOT and pre-compiled queries
79
+
80
+
As mentioned in the introduction, there is a lot of work going on behind the scenes to allow EF Core to run without just-in-time (JIT) compilation. Instead, EF compile ahead-of-time (AOT) everything needed to run queries in the application. This AOT compilation and related processing will happen as part of building and publishing the application. At this point in the EF9 release, there is not much available that can be used by you, the app developer. However, for those interested, the completed issues in EF9 that support AOT and pre-compiled queries are:
81
+
82
+
-[Compiled model: Use static binding instead of reflection for properties and fields](https://github.com/dotnet/efcore/issues/24900)
83
+
-[Compiled model: Generate lambdas used in change tracking](https://github.com/dotnet/efcore/issues/24904)
84
+
-[Make change tracking and the update pipeline compatible with AOT/trimming](https://github.com/dotnet/efcore/issues/29761)
85
+
-[Use interceptors to redirect the query to precompiled code](https://github.com/dotnet/efcore/issues/31331)
86
+
-[Make all SQL expression nodes quotable](https://github.com/dotnet/efcore/issues/33008)
87
+
-[Generate the compiled model during build](https://github.com/dotnet/efcore/issues/24894)
88
+
-[Discover the compiled model automatically](https://github.com/dotnet/efcore/issues/24893)
89
+
-[Make ParameterExtractingExpressionVisitor capable of extracting paths to evaluatable fragments in the tree](https://github.com/dotnet/efcore/issues/32999)
90
+
-[Generate expression trees in compiled models (query filters, value converters)](https://github.com/dotnet/efcore/issues/29924)
91
+
-[Make LinqToCSharpSyntaxTranslator more resilient to multiple declaration of the same variable in nested scopes](https://github.com/dotnet/efcore/issues/32716)
Check back here for examples of how to use pre-compiled queries as the experience comes together.
95
+
23
96
## LINQ and SQL translation
24
97
25
98
The team is working on some significant architecture changes to the query pipeline in EF Core 9 as part of our continued improvements to JSON mapping and document databases. This means we need to get **people like you** to run your code on these new internals. (If you're reading a "What's New" doc at this point in the release, then you're a really engaged part of the community; thank you!) We have over 120,000 tests, but it's not enough! We need you, people running real code on our bits, in order to find issues and ship a solid release!
26
99
100
+
<aname="groupby-complex-types"></a>
101
+
102
+
### GroupBy complex types
103
+
104
+
> [!TIP]
105
+
> The code shown here comes from [ComplexTypesSample.cs](https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/Miscellaneous/NewInEFCore9/ComplexTypesSample.cs).
106
+
107
+
EF9 supports grouping by a complex type instance. For example:
EF translates this as grouping by each member of the complex type, which aligns with the semantics of complex types as value objects. For example, on Azure SQL:
118
+
119
+
```sql
120
+
SELECT [s].[StoreAddress_City], [s].[StoreAddress_Country], [s].[StoreAddress_Line1], [s].[StoreAddress_Line2], [s].[StoreAddress_PostCode], COUNT(*) AS [Count]
121
+
FROM [Stores] AS [s]
122
+
GROUP BY [s].[StoreAddress_City], [s].[StoreAddress_Country], [s].[StoreAddress_Line1], [s].[StoreAddress_Line2], [s].[StoreAddress_PostCode]
123
+
```
124
+
27
125
<aname="prune"></a>
28
126
29
127
### Prune columns passed to OPENJSON's WITH clause
@@ -680,6 +778,66 @@ Now, whenever the model changes, the compiled model will be automatically rebuil
680
778
> [NOTE!]
681
779
> We are working through some performance issues with changes made to the compiled model in EF8 and EF9. See [Issue 33483#](https://github.com/dotnet/efcore/issues/33483) for more information.
682
780
781
+
<aname="read-only-primitives"></a>
782
+
783
+
### Read-only primitive collections
784
+
785
+
> [!TIP]
786
+
> The code shown here comes from [PrimitiveCollectionsSample.cs](https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/Miscellaneous/NewInEFCore9/PrimitiveCollectionsSample.cs).
787
+
788
+
EF8 introduced support for [mapping arrays and mutable lists of primitive types](xref:core/what-is-new/ef-core-8.0/whatsnew#primitive-collections). This has been expanded in EF9 to include read-only collections/lists. Specifically, EF9 supports collections typed as `IReadOnlyList`, `IReadOnlyCollection`, or `ReadOnlyCollection`. For example, in the following code, `DaysVisited` will be mapped by convention as a primitive collection of dates:
The read-only collection can be backed by a normal, mutable collection if desired. For example, in the following code, `DaysVisited` can be mapped as a primitive collection of dates, while still allowing code in the class to manipulate the underlying list.
@@ -770,9 +928,6 @@ CREATE INDEX [IX_User_Name] ON [User] ([Name]) WITH (FILLFACTOR = 80);
770
928
CREATE INDEX [IX_User_Region_Tag] ON [User] ([Region], [Tag]) WITH (FILLFACTOR =80);
771
929
```
772
930
773
-
> [!NOTE]
774
-
> There is currently a bug in preview 2 where the fill-factors are not included when the table is created for the first time. This is tracked by [Issue #33269](https://github.com/dotnet/efcore/issues/33269)
775
-
776
931
This enhancement was contributed by [@deano-hunter](https://github.com/deano-hunter). Many thanks!
0 commit comments