Skip to content

Commit 0a64b75

Browse files
Merge pull request #5333 from dotnet/main
Auto Publish – main to live - 2026-04-14 23:01 UTC
2 parents d956de3 + f70f7a8 commit 0a64b75

9 files changed

Lines changed: 604 additions & 180 deletions

File tree

entity-framework/core/cli/msbuild.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: EF Core MSBuild tasks - EF Core
33
description: Reference guide for the Entity Framework Core .NET MSBuild tasks
44
author: AndriySvyryd
5-
ms.date: 01/17/2025
5+
ms.date: 03/04/2026
66
uid: core/cli/msbuild
77
---
88

@@ -30,14 +30,17 @@ If the project specifies `<PublishAot>true</PublishAot>` then by default the MSB
3030

3131
| MSBuild property | Description |
3232
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
33-
| EFOptimizeContext | Set to `true` to enable MSBuild integration. |
33+
| EFOptimizeContext | Set to `true` to enable MSBuild integration. **EF Core 9-10 only; removed in EF Core 11.** |
3434
| EFScaffoldModelStage | Set to `publish`, `build` or `none` to indicate at which stage the compiled model will be generated. Defaults to `publish`. |
3535
| EFPrecompileQueriesStage | Set to `publish`, `build` or `none` to indicate at which stage the precompiled queries will be generated. Defaults to `publish`. |
3636
| DbContextName | The derived `DbContext` class to use. Class name only or fully qualified with namespaces. If this option is omitted, EF Core will perform generation for all context classes in the project. |
3737
| EFTargetNamespace | The namespace to use for all generated classes. If this option is omitted, EF Core will use `$(RootNamespace)`. |
3838
| EFOutputDir | The folder to put the generated files before the project is compiled. If this option is omitted, EF Core will use `$(IntermediateOutputPath)`. |
3939
| EFNullable | Whether nullable reference types will be used in the generated code. If this option is omitted, EF Core will use `$(Nullable)`. |
4040

41+
> [!NOTE]
42+
> Starting with EF Core 11, the `EFOptimizeContext` property has been [removed](xref:core/what-is-new/ef-core-11.0/breaking-changes#ef-optimize-context-removed). The `EFScaffoldModelStage` and `EFPrecompileQueriesStage` properties now work independently and don't require an additional enablement flag.
43+
4144
## Limitations
4245

4346
* When using the integration during the `publish` stage also set the rid in the startup project (e.g. \<RuntimeIdentifier\>win-x64\</RuntimeIdentifier\>)

entity-framework/core/managing-schemas/migrations/projects.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ uid: core/managing-schemas/migrations/projects
88

99
# Using a Separate Migrations Project
1010

11-
You may want to store your migrations in a different project than the one containing your `DbContext`. You can also use this strategy to maintain multiple sets of migrations, for example, one for development and another for release-to-release upgrades.
11+
You may want to store your migrations in a different project than the one containing your `DbContext`. This is recommended if your project uses a platform-specific project type, such as WinUI, Xamarin, MAUI, Blazor, or Azure Functions, or if it targets a specific runtime identifier (RID). You can also use this strategy to maintain multiple sets of migrations, for example, one for development and another for release-to-release upgrades.
1212

1313
> [!TIP]
1414
> You can view this article's [sample on GitHub](https://github.com/dotnet/EntityFramework.Docs/tree/main/samples/core/Schemas/ThreeProjectMigrations).
@@ -59,3 +59,6 @@ Add-Migration NewMigration -Project WebApplication1.Migrations
5959
```
6060

6161
***
62+
63+
> [!TIP]
64+
> If your application uses dependency injection, consider implementing <xref:Microsoft.EntityFrameworkCore.Design.IDesignTimeDbContextFactory`1> in your migrations project. This allows the EF tools to create your `DbContext` without needing to run the startup project. For more information, see [From a design-time factory](xref:core/cli/dbcontext-creation#from-a-design-time-factory).

entity-framework/core/managing-schemas/migrations/teams.md

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,33 @@
22
title: Migrations in Team Environments - EF Core
33
description: Best practices for managing migrations and resolving conflicts in team environments with Entity Framework Core
44
author: SamMonoRT
5-
ms.date: 10/30/2017
5+
ms.date: 02/18/2026
66
uid: core/managing-schemas/migrations/teams
77
---
88
# Migrations in Team Environments
99

10-
When working with Migrations in team environments, pay extra attention to the model snapshot file. This file can tell you if your teammate's migration merges cleanly with yours or if you need to resolve a conflict by re-creating your
11-
migration before sharing it.
10+
When working with Migrations in team environments, various problems can arise when migrations are added by multiple developers around the same time; note that migrations aren't simply SQL scripts but also include a snapshot of the model at the time of that migration.
1211

13-
## Merging
12+
For example, imagine developer A and B both create work branches at the same time, and generate a migration in their branches. If developer A merges their branch and then developer B does the same, the latest migration (developer B's) will have a context snapshot that does not include the changes from developer A's migration. This can cause various forms of corruption in later migrations.
1413

15-
When you merge migrations from your teammates, you may get conflicts in your model snapshot file. If both changes are unrelated, the merge is trivial and the two migrations can coexist. For example, you may get a merge conflict in the customer entity type configuration that looks like this:
14+
As a result, it is highly recommended to coordinate in advance and to avoid working concurrently on migrations in multiple branches when possible.
1615

17-
```output
18-
<<<<<<< Mine
19-
b.Property<bool>("Deactivated");
20-
=======
21-
b.Property<int>("LoyaltyPoints");
22-
>>>>>>> Theirs
23-
```
16+
## Detecting diverged migration trees
2417

25-
Since both of these properties need to exist in the final model, complete the merge by adding both properties. In many
26-
cases, your version control system may automatically merge such changes for you.
18+
> [!NOTE]
19+
> This feature is being introduced in EF Core 11 from preview-3 onwards.
2720
28-
```csharp
29-
b.Property<bool>("Deactivated");
30-
b.Property<int>("LoyaltyPoints");
31-
```
21+
Starting with EF 11, the model snapshot records the ID of the latest migration. This means that if two developers each create a migration on separate branches, merging those branches will produce a source control conflict in the model snapshot file — since both branches modify the latest migration ID. This conflict is an important signal: it tells you that the migration trees have diverged, and one of them must be discarded before proceeding.
3222

33-
In these cases, your migration and your teammate's migration are independent of each other. Since either of them could be applied first, you don't need to make any additional changes to your migration before sharing it with your team.
23+
To resolve this, follow the steps in [Resolving diverged migration trees](#resolving-diverged-migration-trees) below: abort the merge, remove your migration (keeping your model changes), merge your teammate's changes, and then re-add your migration.
3424

35-
## Resolving conflicts
25+
## Resolving diverged migration trees
3626

37-
Sometimes you encounter a true conflict when merging the model snapshot model. For example, you and your teammate may each have renamed the same property.
38-
39-
```output
40-
<<<<<<< Mine
41-
b.Property<string>("Username");
42-
=======
43-
b.Property<string>("Alias");
44-
>>>>>>> Theirs
45-
```
46-
47-
If you encounter this kind of conflict, resolve it by re-creating your migration. Follow these steps:
27+
If, when merging a branch, a diverged migration tree is detected, resolve it by re-creating your migration. Follow these steps:
4828

4929
1. Abort the merge and rollback to your working directory before the merge
5030
2. Remove your migration (but keep your model changes)
5131
3. Merge your teammate's changes into your working directory
5232
4. Re-add your migration
5333

54-
After doing this, the two migrations can be applied in the correct order. Their migration is applied first, renaming
55-
the column to *Alias*, thereafter your migration renames it to *Username*.
56-
57-
Your migration can safely be shared with the rest of the team.
34+
After doing this, your migration is cleanly based on top of any migrations that have been added in the other branch, and its context snapshot contains all previous changes. Your migration can now be safely shared with the rest of the team.

entity-framework/core/modeling/relationships/foreign-and-principal-keys.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,32 @@ This can be changed in the model building API using `HasConstraintName`. For exa
189189
> [!TIP]
190190
> The constraint name is not used by the EF runtime. It is only used when creating a database schema using [EF Core Migrations](xref:core/managing-schemas/migrations/index).
191191
192+
### Excluding foreign key constraints from migrations
193+
194+
> [!NOTE]
195+
> This feature is being introduced in EF Core 11, which is currently in preview.
196+
197+
Sometimes it is useful to have the foreign key relationship represented in the EF model, but without creating the corresponding foreign key constraint in the database. This can happen with legacy databases where constraints don't exist, or in data synchronization scenarios where the order of inserting related entities might temporarily violate referential integrity constraints. In these cases, use `ExcludeForeignKeyFromMigrations` to prevent EF from generating the foreign key constraint in migrations (and `EnsureCreated`):
198+
199+
```csharp
200+
modelBuilder.Entity<Blog>()
201+
.HasMany(e => e.Posts)
202+
.WithOne(e => e.Blog)
203+
.HasForeignKey(e => e.BlogId)
204+
.ExcludeForeignKeyFromMigrations();
205+
```
206+
207+
With this configuration, EF will not create a foreign key constraint in the database, but the relationship is still tracked in the EF model and can be used normally for loading related data, change tracking, etc. EF will still create a database index for the foreign key column, since indexes benefit queries regardless of whether a constraint exists.
208+
209+
To apply this across all foreign keys in the model (e.g. to globally disable all foreign key constraints), you can iterate over all foreign keys in `OnModelCreating`:
210+
211+
```csharp
212+
foreach (var foreignKey in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
213+
{
214+
foreignKey.SetIsExcludedFromMigrations(true);
215+
}
216+
```
217+
192218
### Indexes for foreign keys
193219

194220
By convention, EF creates a database index for the property or properties of a foreign key. See [_Model building conventions_](xref:core/modeling/relationships/conventions) for more information about the types of indexes created by convention.

entity-framework/core/providers/sql-server/functions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ stringValue.Trim() | LTRIM(
232232
stringValue.TrimEnd() | RTRIM(@stringValue)
233233
stringValue.TrimStart() | LTRIM(@stringValue)
234234

235+
## JSON functions
236+
237+
.NET | SQL | Added in
238+
----------------------------------------------------------------- | --------------------------------------------------------- | --------
239+
EF.Functions.JsonContains(json, searchValue, path?, searchMode?) | JSON_CONTAINS(@json, @searchValue, @path?, @searchMode?) | EF 11.0
240+
EF.Functions.JsonPathExists(json, path) | JSON_PATH_EXISTS(@json, @path) | EF 11.0
241+
235242
## Miscellaneous functions
236243

237244
.NET | SQL | Added in

entity-framework/core/providers/sql-server/vector-search.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ await context.SaveChangesAsync();
6666

6767
Once you have embeddings saved to your database, you're ready to perform vector similarity search over them.
6868

69+
> [!NOTE]
70+
> Starting with EF Core 11, vector properties are not loaded by default when querying entities, since vectors are typically large and are rarely needed to be read back. Prior to EF Core 11, vector properties were always loaded like any other property.
71+
6972
## Exact search with VECTOR_DISTANCE()
7073

7174
The [`EF.Functions.VectorDistance()`](/sql/t-sql/functions/vector-distance-transact-sql) function computes the *exact* distance between two vectors. Use it to perform similarity search for a given user query:
@@ -126,7 +129,7 @@ Once you have a vector index, use the `VectorSearch()` extension method on your
126129

127130
```csharp
128131
var blogs = await context.Blogs
129-
.VectorSearch(b => b.Embedding, "cosine", embedding, topN: 5)
132+
.VectorSearch(b => b.Embedding, embedding, "cosine", topN: 5)
130133
.ToListAsync();
131134

132135
foreach (var (blog, score) in blogs)
@@ -138,7 +141,7 @@ foreach (var (blog, score) in blogs)
138141
This translates to the following SQL:
139142

140143
```sql
141-
SELECT [v].[Id], [v].[Embedding], [v].[Name]
144+
SELECT [v].[Id], [v].[Name], [v].[Distance]
142145
FROM VECTOR_SEARCH([Blogs], 'Embedding', @__embedding, 'metric = cosine', @__topN)
143146
```
144147

@@ -148,7 +151,7 @@ The `topN` parameter specifies the maximum number of results to return.
148151

149152
```csharp
150153
var searchResults = await context.Blogs
151-
.VectorSearch(b => b.Embedding, "cosine", embedding, topN: 5)
154+
.VectorSearch(b => b.Embedding, embedding, "cosine", topN: 5)
152155
.Where(r => r.Distance < 0.05)
153156
.Select(r => new { Blog = r.Value, Distance = r.Distance })
154157
.ToListAsync();
@@ -206,7 +209,7 @@ This query:
206209
The query produces the following SQL:
207210

208211
```sql
209-
SELECT TOP(@p3) [a0].[Id], [a0].[Content], [a0].[Embedding], [a0].[Title]
212+
SELECT TOP(@p3) [a0].[Id], [a0].[Content], [a0].[Title]
210213
FROM FREETEXTTABLE([Articles], *, @p, @p1) AS [f]
211214
LEFT JOIN VECTOR_SEARCH(
212215
TABLE = [Articles] AS [a0],

0 commit comments

Comments
 (0)