Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken links in porting guide #3672

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions entity-framework/efcore-and-ef6/porting/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ uid: efcore-and-ef6/porting/index
Entity Framework Core, or EF Core for short, is a total rewrite of Entity Framework for modern application architectures. Due to fundamental changes, there is not a direct upgrade path. The purpose of this documentation is to provide an end-to-end guide for porting your EF6 applications to EF Core.

> [!IMPORTANT]
> Before you start the porting process it is important to validate that EF Core meets the data access requirements for your application. You can find everything you need in the [EF Core documentation](/ef/core/).
> Before you start the porting process it is important to validate that EF Core meets the data access requirements for your application. You can find everything you need in the [EF Core documentation](xref:core/index).

> [!IMPORTANT]
> There is a known issue ([microsoft/dotnet-apiport #993](https://github.com/microsoft/dotnet-apiport/issues/993)) with the [portability analyzer](/dotnet/standard/analyzers/portability-analyzer) that erroneously reports EF Core as incompatible with .NET 5 and .NET 6. These warnings can be safely ignored as EF Core is 100% compatible with .NET 5 and .NET 6 target frameworks.
Expand All @@ -20,13 +20,13 @@ Entity Framework Core, or EF Core for short, is a total rewrite of Entity Framew

All new Entity Framework development is happening in EF Core. There are no plans to backport any new features to EF6. EF Core runs on the latest .NET runtimes and takes full advantage of runtime, platform-specific (such as ASP.NET Core or WPF) and language-specific features. Here are a few of the benefits you gain from upgrading:

- Take advantage of the ongoing **performance improvements** in EF Core. For example, one customer who migrated from EF6 to EF Core 6 saw a 40x reduction in use of a heavy query due to the [query splitting feature](/ef/core/querying/single-split-queries/). Many customers report enormous performance gains simply by moving to the latest EF Core.
- Use **new features** in EF Core. There will be no new features added to EF6. All of the new functionality, for example the [Azure Cosmos DB provider](/ef/core/providers/cosmos/) and [`DbContextFactory`](/ef/core/what-is-new/ef-core-5.0/whatsnew#dbcontextfactory), will only be added to EF Core. For a full comparison of EF6 to EF Core, including several features exclusive to EF Core, see: [Compare EF Core & EF6](/ef/efcore-and-ef6/).
- Take advantage of the ongoing **performance improvements** in EF Core. For example, one customer who migrated from EF6 to EF Core 6 saw a 40x reduction in use of a heavy query due to the [query splitting feature](xref:core/querying/single-split-queries). Many customers report enormous performance gains simply by moving to the latest EF Core.
- Use **new features** in EF Core. There will be no new features added to EF6. All of the new functionality, for example the [Azure Cosmos DB provider](xref:core/providers/cosmos/index) and [`DbContextFactory`](xref:core/what-is-new/ef-core-5.0/whatsnew#dbcontextfactory), will only be added to EF Core. For a full comparison of EF6 to EF Core, including several features exclusive to EF Core, see: [Compare EF Core & EF6](xref:efcore-and-ef6/index).
- **Modernize your application stack** by using dependency injection and seamlessly integrate your data access with technologies like gRPC and GraphQL.

## A note on migrations

This documentation uses the terms _port_ and _upgrade_ to avoid confusion with the term [_migrations_](/ef/core/managing-schemas/migrations/) as a feature of EF Core. Migrations in EF Core are not compatible with [EF6 Code First migrations](/ef/ef6/modeling/code-first/migrations/) due to significant improvements to how migrations are handled. There is not a recommended approach to port your migrations history, so plan to start "fresh" in EF Core. You can maintain the codebase and data from your EF6 migrations. Apply your final migration in EF6, then create an initial migration in EF Core. You will be able to track history in EF Core moving forward.
This documentation uses the terms _port_ and _upgrade_ to avoid confusion with the term [_migrations_](xref:core/managing-schemas/migrations/index) as a feature of EF Core. Migrations in EF Core are not compatible with [EF6 Code First migrations](xref:ef6/modeling/code-first/migrations/index) due to significant improvements to how migrations are handled. There is not a recommended approach to port your migrations history, so plan to start "fresh" in EF Core. You can maintain the codebase and data from your EF6 migrations. Apply your final migration in EF6, then create an initial migration in EF Core. You will be able to track history in EF Core moving forward.

## Upgrade steps

Expand Down Expand Up @@ -54,21 +54,21 @@ The hybrid approach is a more advanced approach with additional overhead compare

### Understand the impact of moving away from EDMX

EF6 supported a special model definition format named *Entity Data Model XML (EDMX)*. EDMX files contain multiple definitions, including conceptual schema definitions (CSDL), mapping specifications (MSL), and store schema definitions (SSDL). EF Core tracks the domain, mapping, and database schemas through internal model graphs and does not support the EDMX format. Many blog posts and articles mistakenly state this means EF Core only supports "code first." EF Core supports all three application models described in the previous section. You can rebuild the model in EF Core by [reverse-engineering the database](/ef/core/managing-schemas/scaffolding). If you use EDMX for a visual representation of your entity model, consider using the open source [EF Core Power Tools](https://github.com/ErikEJ/EFCorePowerTools) that provide similar capabilities for EF Core.
EF6 supported a special model definition format named *Entity Data Model XML (EDMX)*. EDMX files contain multiple definitions, including conceptual schema definitions (CSDL), mapping specifications (MSL), and store schema definitions (SSDL). EF Core tracks the domain, mapping, and database schemas through internal model graphs and does not support the EDMX format. Many blog posts and articles mistakenly state this means EF Core only supports "code first." EF Core supports all three application models described in the previous section. You can rebuild the model in EF Core by [reverse-engineering the database](xref:core/managing-schemas/scaffolding). If you use EDMX for a visual representation of your entity model, consider using the open source [EF Core Power Tools](https://github.com/ErikEJ/EFCorePowerTools) that provide similar capabilities for EF Core.

For more information on the impact of lack of support for EDMX files, read the [porting EDMX](/ef/efcore-and-ef6/porting/port-edmx#other-considerations) guide.
For more information on the impact of lack of support for EDMX files, read the [porting EDMX](xref:efcore-and-ef6/porting/port-edmx#other-considerations) guide.

### Perform the upgrade steps

It is not a requirement to port the entire application. EF6 and EF Core can run in the same application (see: [using EF Core and EF6 in the same application](/ef/efcore-and-ef6/side-by-side?branch=pr-en-us-3509)). To minimize risk, you might consider:
It is not a requirement to port the entire application. EF6 and EF Core can run in the same application (see: [using EF Core and EF6 in the same application](xref:efcore-and-ef6/side-by-side)). To minimize risk, you might consider:

1. Move to EF6 on .NET Core if you haven't already.
1. Migrate a small portion of your app to EF Core and run it side-by-side with EF6.
1. Eventually bring the rest of the codebase to EF Core and retire the EF6 code.

As for the port itself, at a high level, you will:

1. [Review behavior changes between EF6 and EF Core](/ef/efcore-and-ef6/porting/port-behavior).
1. [Review behavior changes between EF6 and EF Core](xref:efcore-and-ef6/porting/port-behavior).
1. Perform your final migrations, if any, in EF6.
1. Create your EF Core project.
1. Either copy code to the new project, run reverse-engineering, or a combination of both.
Expand All @@ -78,12 +78,12 @@ As for the port itself, at a high level, you will:
- `DbModelBuilder` to `ModelBuilder`
- Rename `DbEntityEntry<T>` to `EntityEntry<T>`
- Move from `Database.Log` to `Microsoft.Extensions.Logging` (advanced) or `DbContextOptionsBuilder.LogTo` (simple) APIs
- Apply changes for `WithRequired` and `WithOptional` (see [here](/ef/efcore-and-ef6/porting/port-detailed-cases#required-and-optional))
- Apply changes for `WithRequired` and `WithOptional` (see [here](xref:efcore-and-ef6/porting/port-detailed-cases#required-and-optional))
- Update validation code. There is no data validation built into EF Core, but you can [do it yourself](/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/domain-model-layer-validations#use-validation-attributes-in-the-model-based-on-data-annotations).
- Follow any necessary steps to [port from EDMX](/ef/efcore-and-ef6/porting/port-edmx).
- Follow any necessary steps to [port from EDMX](xref:efcore-and-ef6/porting/port-edmx).
1. Perform specific steps based on your EF Core approach:
- [Code as source of truth](/ef/efcore-and-ef6/porting/port-code.md)
- [Database as source of truth](/ef/efcore-and-ef6/porting/port-database.md)
- [Hybrid model](/ef/efcore-and-ef6/porting/port-hybrid.md)
- [Code as source of truth](xref:efcore-and-ef6/porting/port-code)
- [Database as source of truth](xref:efcore-and-ef6/porting/port-database)
- [Hybrid model](xref:efcore-and-ef6/porting/port-hybrid)

There are many considerations that relate to all of the approaches, so you will also want to review ways to address and work around the [detailed differences between EF6 and EF Core](/ef/efcore-and-ef6/porting/port-detailed-cases.md).
There are many considerations that relate to all of the approaches, so you will also want to review ways to address and work around the [detailed differences between EF6 and EF Core](xref:efcore-and-ef6/porting/port-detailed-cases).
6 changes: 3 additions & 3 deletions entity-framework/efcore-and-ef6/porting/port-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ uid: efcore-and-ef6/porting/port-behavior

This is a non-exhaustive list of changes in behavior between EF6 and EF Core. It is important to keep these in mind as your port your application as they may change the way your application behaves, but will not show up as compilation errors after swapping to EF Core.

This is meant as a high level review to consider as part of the porting process. For more detailed, case-by-case instructions, read the [detailed cases](/efcore-and-ef6/porting/port-detailed-cases).
This is meant as a high level review to consider as part of the porting process. For more detailed, case-by-case instructions, read the [detailed cases](xref:efcore-and-ef6/porting/port-detailed-cases).

## DbSet.Add/Attach and graph behavior

Expand All @@ -30,7 +30,7 @@ The general philosophy here is that `Update` is a very simple way to handle inse

At the same time, `Add` still provides an easy way force entities to be inserted. Add is mostly useful only when not using store-generated keys, such that EF doesn't know if the entity is new or not.

For more information on these behaviors in EF Core, read [Change Tracking in EF Core](/ef/core/change-tracking/).
For more information on these behaviors in EF Core, read [Change Tracking in EF Core](xref:core/change-tracking/index).

## Code First database initialization

Expand All @@ -53,4 +53,4 @@ EF6 runs the entity class name through a pluralization service to calculate the

EF Core uses the name of the `DbSet` property that the entity is exposed in on the derived context. If the entity does not have a `DbSet` property, then the class name is used.

For more information, read [Managing Database Schemas](/ef/core/managing-schemas/).
For more information, read [Managing Database Schemas](xref:core/managing-schemas/index).
4 changes: 2 additions & 2 deletions entity-framework/efcore-and-ef6/porting/port-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Most APIs that you use in EF6 are in the `System.Data.Entity` namespace (and rel

## Context configuration (connection etc.)

As described in [configuring the database connection](/ef/efcore-and-ef6/porting/port-detailed-cases?#configuring-the-database-connection), EF Core has less magic around detecting the database to connect to. You will need to override the `OnConfiguring` method on your derived context, and use the database provider specific API to setup the connection to the database.
As described in [configuring the database connection](xref:efcore-and-ef6/porting/port-detailed-cases#configuring-the-database-connection), EF Core has less magic around detecting the database to connect to. You will need to override the `OnConfiguring` method on your derived context, and use the database provider specific API to setup the connection to the database.

Most EF6 applications store the connection string in the applications `App/Web.config` file. In EF Core, you read this connection string using the `ConfigurationManager` API. You may need to add a reference to the `System.Configuration` framework assembly to be able to use this API.

Expand Down Expand Up @@ -54,4 +54,4 @@ If possible, it is best to assume that all previous migrations from EF6 have bee

Just because your application compiles, does not mean it is successfully ported to EF Core. You will need to test all areas of your application to ensure that none of the behavior changes have adversely impacted your application.

Finally, review the [detailed cases to consider when porting](/ef/efcore-and-ef6/porting/port-detailed-cases) for more advice on specific cases and scenarios in your code.
Finally, review the [detailed cases to consider when porting](xref:efcore-and-ef6/porting/port-detailed-cases) for more advice on specific cases and scenarios in your code.
12 changes: 6 additions & 6 deletions entity-framework/efcore-and-ef6/porting/port-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ If you're using the database as the source of truth, the upgrade will mostly inv
1. Pick a point-in-time to model the database.
1. Ensure your EF6 projects are up to date and in-sync with the database.
1. Create the EF Core project.
1. Use the [scaffolding tools](/ef/core/managing-schemas/scaffolding) to reverse-engineer your database to code.
1. Use the [scaffolding tools](xref:core/managing-schemas/scaffolding) to reverse-engineer your database to code.
1. Validate that the EF Core generated classes are compatible with your code.
1. For exceptions, either modify the generated classes and update the [model configuration](/ef/core/modeling/) or adapt your code to the model.
1. For exceptions, either modify the generated classes and update the [model configuration](xref:core/modeling/index) or adapt your code to the model.

Note that although EF Core currently scaffolds everything needed to successfully generate a copy of the database, much of the code is not needed for the database-first approach. A fix for this is tracked in [Issue #10890](/dotnet/efcore/issues/10890). Things that you can safely ignore as not needed include: sequences, constraint names, non-unique indexes and index filters.
Note that although EF Core currently scaffolds everything needed to successfully generate a copy of the database, much of the code is not needed for the database-first approach. A fix for this is tracked in [Issue #10890](https://github.com/dotnet/efcore/issues/10890). Things that you can safely ignore as not needed include: sequences, constraint names, non-unique indexes and index filters.

## Handling schema changes

Expand All @@ -30,10 +30,10 @@ For various reasons, you may want your C# domain model to be shaped differently

If your model is significantly different from the generated one, but doesn't change frequently, one option to consider is use of the [repository pattern](/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-design) as an adapter. The repository can consume the EF Core generated classes and publish the custom classes you use. This may reduce the impact of changes by isolating them to the repository code, rather than having to perform an application-wide refactoring each time the schema changes.

You may want to consider an alternate workflow and follow steps similar to the [hybrid approach](/ef/efcore-and-ef6/porting/port-hybrid). Instead of generating a new set of classes each time, you indicate specific tables to only generate new classes. You keep existing classes "as is" and directly add or remove properties that changed. You then update the model configuration to address any changes in how the database maps to your existing classes.
You may want to consider an alternate workflow and follow steps similar to the [hybrid approach](xref:efcore-and-ef6/porting/port-hybrid). Instead of generating a new set of classes each time, you indicate specific tables to only generate new classes. You keep existing classes "as is" and directly add or remove properties that changed. You then update the model configuration to address any changes in how the database maps to your existing classes.

## Customize the code generation

EF Core 6 currently does not support customization of the generated code. There are third party solutions like [EF Core Power Tools](https://github.com/ErikEJ/EFCorePowerTools/wiki) that are available. For a list of featured community tools and extensions, see: [EF Core Tools and Extensions](/ef/core/extensions/).
EF Core 6 currently does not support customization of the generated code. There are third party solutions like [EF Core Power Tools](https://github.com/ErikEJ/EFCorePowerTools/wiki) that are available. For a list of featured community tools and extensions, see: [EF Core Tools and Extensions](xref:core/extensions/index).

Finally, review the [detailed list of differences between EF6 and EF Core](/ef/efcore-and-ef6/porting/port-detailed-cases) to address any remaining issues with porting.
Finally, review the [detailed list of differences between EF6 and EF Core](xref:efcore-and-ef6/porting/port-detailed-cases) to address any remaining issues with porting.
Loading