|
1 | 1 | # Entity Framework Core in .NET 10 RC 1 - Release Notes
|
2 | 2 |
|
3 |
| -The following .NET 10 RC 1 release notes describe new features and changes in |
4 |
| -this release. |
| 3 | +Entity Framework Core 10 updates: |
5 | 4 |
|
6 |
| -## What's new features |
| 5 | +- [What's new in Entity Framework Core 10](https://learn.microsoft.com/ef/core/what-is-new/ef-core-10.0/whatsnew) documentation |
| 6 | +- [Breaking change in Entity Framework Core 10](https://learn.microsoft.com/ef/core/what-is-new/ef-core-10.0/breaking-changes) |
7 | 7 |
|
8 |
| -TBD |
| 8 | +The following .NET 10 RC 1 release notes describe new features and changes in this release. |
| 9 | + |
| 10 | +## SQL Server vector search |
| 11 | + |
| 12 | +EF 10 brings full support for the recently-introduced vector data type and its supporting VECTOR_DISTANCE() function, available on Azure SQL Database and on SQL Server 2025. |
| 13 | + |
| 14 | +To use the vector data type, simply add a .NET property of type `SqlVector<float>` to your entity type: |
| 15 | + |
| 16 | +```c# |
| 17 | +public class Blog |
| 18 | +{ |
| 19 | + // ... |
| 20 | +
|
| 21 | + [Column(TypeName = "vector(1536)")] |
| 22 | + public SqlVector<float> Embedding { get; set; } |
| 23 | +} |
| 24 | +``` |
| 25 | + |
| 26 | +Then, insert embedding data by populating the Embedding property and calling SaveChangesAsync() as usual: |
| 27 | + |
| 28 | +```c# |
| 29 | +IEmbeddingGenerator<string, Embedding<float>> embeddingGenerator = /* Set up your preferred embedding generator */; |
| 30 | + |
| 31 | +var embedding = await embeddingGenerator.GenerateVectorAsync("Some text to be vectorized"); |
| 32 | +context.Blogs.Add(new Blog |
| 33 | +{ |
| 34 | + Name = "Some blog", |
| 35 | + Embedding = new SqlVector<float>(embedding) |
| 36 | +}); |
| 37 | +await context.SaveChangesAsync(); |
| 38 | +``` |
| 39 | + |
| 40 | +For more information on vector search, [see the documentation](https://learn.microsoft.com/ef/core/providers/sql-server/vector-search). |
| 41 | + |
| 42 | +## SQL Server JSON type support |
| 43 | + |
| 44 | +EF 10 fully supports the new JSON data type, available on Azure SQL Database and on SQL Server 2025: |
| 45 | + |
| 46 | +```c# |
| 47 | +public class Blog |
| 48 | +{ |
| 49 | + public int Id { get; set; } |
| 50 | + |
| 51 | + public string[] Tags { get; set; } |
| 52 | + public required BlogDetails Details { get; set; } |
| 53 | +} |
| 54 | + |
| 55 | +public class BlogDetails |
| 56 | +{ |
| 57 | + public string? Description { get; set; } |
| 58 | + public int Viewers { get; set; } |
| 59 | +} |
| 60 | + |
| 61 | +protected override void OnModelCreating(ModelBuilder modelBuilder) |
| 62 | +{ |
| 63 | + modelBuilder.Entity<Blog>().ComplexProperty(b => b.Details, b => b.ToJson()); |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +When configured to target SQL Server 2025, EF 10 creates the following table for the above: |
| 68 | + |
| 69 | +```sql |
| 70 | +CREATE TABLE [Blogs] ( |
| 71 | + [Id] int NOT NULL IDENTITY, |
| 72 | + [Name] nvarchar(max) NOT NULL, |
| 73 | + [Tags] json NOT NULL, |
| 74 | + [Details] json NOT NULL, |
| 75 | + CONSTRAINT [PK_Blogs] PRIMARY KEY ([Id]) |
| 76 | +); |
| 77 | +``` |
| 78 | + |
| 79 | +For more information, [see the EF what's new page](https://learn.microsoft.com/ef/core/what-is-new/ef-core-10.0/whatsnew#json-type-support). |
| 80 | + |
| 81 | +## Cosmos full-text and hybrid search |
| 82 | + |
| 83 | +EF 10 brings support for the new Cosmos full-text feature: |
| 84 | + |
| 85 | +```c# |
| 86 | +protected override void OnModelCreating(ModelBuilder modelBuilder) |
| 87 | +{ |
| 88 | + modelBuilder.Entity<Blog>(b => |
| 89 | + { |
| 90 | + b.Property(x => x.Contents).EnableFullTextSearch(); |
| 91 | + b.HasIndex(x => x.Contents).IsFullTextIndex(); |
| 92 | + }); |
| 93 | +} |
| 94 | + |
| 95 | +var cosmosBlogs = await context.Blogs |
| 96 | + .Where(x => EF.Functions.FullTextContains(x.Contents, "cosmos")) |
| 97 | + .ToListAsync(); |
| 98 | +``` |
| 99 | + |
| 100 | +The new hybrid search capability, which allows combining full-text and vector search, is also supported: |
| 101 | + |
| 102 | +```c# |
| 103 | +float[] myVector = /* generate vector data from text, image, etc. */ |
| 104 | +var hybrid = await context.Blogs.OrderBy(x => EF.Functions.Rrf( |
| 105 | + EF.Functions.FullTextScore(x.Contents, "database"), |
| 106 | + EF.Functions.VectorDistance(x.Vector, myVector))) |
| 107 | + .Take(10) |
| 108 | + .ToListAsync(); |
| 109 | +``` |
| 110 | + |
| 111 | +For more information, [see the documentation](https://learn.microsoft.com/ef/core/providers/cosmos/full-text-search). |
| 112 | + |
| 113 | +## Complex types |
| 114 | + |
| 115 | +EF 10 introduces substantially improved support for *complex types*, which are designed to map nested types to the database, either via JSON or by mapping their columns to the same table as their container: |
| 116 | + |
| 117 | +```c# |
| 118 | +modelBuilder.Entity<Customer>(b => |
| 119 | +{ |
| 120 | + // Maps the columns of ShippingAddress to the Customer table |
| 121 | + b.ComplexProperty(c => c.ShippingAddress); |
| 122 | + // Maps BillingAddress to a single JSON column in the Customer table |
| 123 | + b.ComplexProperty(c => c.BillingAddress, c => c.ToJson()); |
| 124 | +}); |
| 125 | +``` |
| 126 | + |
| 127 | +Once your nested type has been mapped, it can be fully queried via LINQ and updated via the usual EF mechanisms. Note that while EF has supported nested mapping via owned entity types, complex types represent a better alternative that fixes many of the problems encountered with owned entity types. |
| 128 | + |
| 129 | +Note that this the complex type support was considerably improved after RC1, and many bugs have been fixed for RC2; to use the full extent of the feature, it's advised to wait for RC2. |
| 130 | + |
| 131 | +## Padding for parameterized collections |
| 132 | + |
| 133 | +Building on top of the improved translation for parameterized collection introduced in preview 7 ([docs](https://github.com/dotnet/core/blob/main/release-notes/10.0/preview/preview7/efcore.md#improved-translation-for-parameterized-collection)), in RC1 EF also introduces parameter padding, which further optimizes the generated SQL. [See the EF what's new page for more details](https://learn.microsoft.com/ef/core/what-is-new/ef-core-10.0/whatsnew#improved-translation-for-parameterized-collection). |
| 134 | + |
| 135 | +## Everything else in RC1 |
| 136 | + |
| 137 | +The full list of issues completed for RC1 can be found [here](https://github.com/dotnet/efcore/issues?q=is%3Aissue%20state%3Aclosed%20label%3Arc-1). |
0 commit comments