针对 Entity Framework Core 5.0 的计划Plan for Entity Framework Core 5.0

计划过程中所述,我们已来自利益干系人的输入收集到针对 EF Core 5.0 版的暂定计划中。As described in the planning process, we have gathered input from stakeholders into a tentative plan for the EF Core 5.0 release.

重要

此计划仍是半成品。This plan is still a work-in-progress. 这里不进行任何承诺。Nothing here is a commitment. 此计划是一个起点,会随着我们了解更多信息而发展。This plan is a starting point that will evolve as we learn more. 当前未针对 5.0 进行计划的某些内容可能会被纳入。Some things not currently planned for 5.0 may get pulled in. 当前已针对 5.0 进行计划的某些内容可能会被淘汰。Some things currently planned for 5.0 may get punted out.

常规信息General information

版本号和发布日期Version number and release date

EF Core 5.0 当前计划与 .NET 5.0 同时发布。EF Core 5.0 is currently scheduled for release at the same time as .NET 5.0. 已选择版本“5.0”,以便与 .NET 5.0 保持一致。The version "5.0" was chosen to align with .NET 5.0.

受支持的平台Supported platforms

EF Core 5.0 计划在任何 .NET Standard 2.1 平台(包括 .NET 5.0)上运行。EF Core 5.0 is planned to run on any .NET Standard 2.1 platform, including .NET 5.0. 这是更常见的 .NET 范围平台与 .NET Core 的聚合的一部分。This is part of the more general .NET wide convergence of platforms to .NET Core.

EF Core 5.0 不会在 .NET Framework 上运行。EF Core 5.0 will not run on .NET Framework.

重大更改Breaking changes

EF Core 5.0 将包含一些中断性变更,但与 EF Core 3.0 的情况相比,这些更改的严重性要小得多。EF Core 5.0 will contain some breaking changes, but these will be much less severe than was the case for EF Core 3.0. 我们的目标是允许大多数应用程序进行更新而不会中断。Our goal is to allow the vast majority of applications to update without breaking.

预计会对数据库提供程序进行一些重大更改,尤其是在 TPT 支持方面。It is expected that there will be some breaking changes for database providers, especially around TPT support. 但是,我们预计为 5.0 更新提供程序的工作会少于为 3.0 更新所需的工作。However, we expect the work to update a provider for 5.0 will be less than was required to update for 3.0.

主题Themes

我们提取了几个主要领域或主题,它们将构成对 EF Core 5.0 进行大量投入的基础。We have extracted a few major areas or themes which will form the basis for the large investments in EF Core 5.0.

以完全透明的方式按约定进行多对多映射Fully transparent many-to-many mapping by convention

主要开发人员:@smitpatel、@AndriySvyryd 和 @lajonesLead developers: @smitpatel, @AndriySvyryd, and @lajones

通过 #10508 进行跟踪Tracked by #10508

T 恤大小:LT-shirt size: L

状态:完成Status: Done

多对多是 GitHub 积压工作 (backlog) 中请求最多的功能(大约 506 张投票)。Many-to-many is the most requested feature (~506 votes) on the GitHub backlog.

多对多关系的支持分为三个主要方面:Support for many-to-many relationships can be broken down into three major areas:

  • 跳过导航属性 - 将在下个主题中讲解它们。Skip navigation properties--covered by the next theme.
  • 属性包实体类型。Property-bag entity types. 这些类型使标准 CLR 类型(例如 Dictionary)可以用于实体实例,使得每种实体类型都不需要显式 CLR 类型。These allow a standard CLR type (e.g. Dictionary) to be used for entity instances such that an explicit CLR type is not needed for each entity type. 通过 #9914 进行跟踪。Tracked by #9914.
  • Sugar 可用于轻松配置多对多关系。Sugar for easy configuration of many-to-many relationships.

除了支持跳过导航,我们现还将多对多关系的这些其他方面引入到 EF Core 5.0 来提供完整的体验。In addition to the skip navigation support, we are now pulling these other areas of many-to-many into EF Core 5.0 so as to provide a complete experience.

多对多导航属性(即“跳过导航”)Many-to-many navigation properties (a.k.a "skip navigations")

开发人员负责人:@smitpatel 和 @AndriySvyrydLead developers: @smitpatel and @AndriySvyryd

通过 #19003 进行跟踪Tracked by #19003

T 恤大小:LT-shirt size: L

状态:完成Status: Done

如第一个主题中所述,多对多支持具有多个方面。As described in the first theme, many-to-many support has multiple aspects. 该主题专门跟踪对跳过导航功能的使用。This theme specifically tracks use of skip navigations. 我们认为,对于需要多对多支持的人员而言,最重要的阻止因素是无法在业务逻辑(如查询)中使用“自然”关系,而无需引用联接表。We believe that the most significant blocker for those wanting many-to-many support is not being able to use the "natural" relationships, without referring to the join table, in business logic such as queries. 联接表实体类型可能仍然存在,但不应妨碍业务逻辑。The join table entity type may still exist, but it should not get in the way of business logic.

每个类型一张表 (TPT) 继承映射Table-per-type (TPT) inheritance mapping

开发人员主管:@AndriySvyryd 和 @smitpatelLead developer: @AndriySvyryd and @smitpatel

通过 #2266 进行跟踪Tracked by #2266

T 恤大小:XLT-shirt size: XL

状态:完成Status: Done

我们要实现 TPT 是因为它是经常请求的功能(大约 289 张投票;第三名),并且它需要一些低级更改,我们认为这些更改适合于总体 .NET 5 计划的基础性质。We're doing TPT because it is both a highly requested feature (~289 votes; 3rd overall) and because it requires some low-level changes that we feel are appropriate for the foundational nature of the overall .NET 5 plan. 我们预计这会形成数据库提供程序的重大更改,但与 3.0 所需的更改相比,这些更改的严重性要小得多。We expect this to result in breaking changes for database providers, although these should be much less severe than the changes required for 3.0.

经过筛选的包含Filtered Include

开发人员负责人:@maumarLead developer: @maumar

通过 #1833 进行跟踪Tracked by #1833

T 恤大小:MT-shirt size: M

状态:完成Status: Done

经过筛选的包含是经常请求的功能(大约 376 张投票;第二名),其工作量不大,我们认为这会使当前需要模型级筛选器或更复杂查询的许多方案不受阻碍或更加容易。Filtered Include is a highly-requested feature (~376 votes; 2nd overall) that isn't a huge amount of work, and that we believe will unblock or make easier many scenarios that currently require model-level filters or more complex queries.

拆分 IncludeSplit Include

开发人员负责人:@smitpatelLead developer: @smitpatel

通过 #20892 进行跟踪Tracked by #20892

T 恤大小:LT-shirt size: L

状态:完成Status: Done

EF Core 3.0 更改了默认行为,它为给定的 LINQ 查询创建一个 SQL 查询。EF Core 3.0 changed the default behavior to create a single SQL query for a given LINQ query. 对于使用 Include 来处理多个集合的查询来说,这导致性能大幅下降。This caused large performance regressions for queries that use Include for multiple collections.

在 EF Core 5.0 中,我们将保留新的默认行为。In EF Core 5.0, we are retaining the new default behavior. 不过,EF Core 5.0 现在允许为集合 Includes 生成多个查询,因为使用单个查询会导致性能不佳。However, EF Core 5.0 will now allow generation of multiple queries for collection Includes where having a single query is causing bad performance.

需要一对一依赖项Required one-to-one dependents

开发人员负责人:@AndriySvyryd 和 @smitpatelLead developers: @AndriySvyryd and @smitpatel

通过 #12100 进行跟踪Tracked by #12100

T 恤大小:MT-shirt size: M

状态:完成Status: Done

在 EF Core 3.0 中,所有依赖项(包括所拥有的类型)都是可选的(例如 Person.Address 可为 null)。In EF Core 3.0, all dependents, including owned types are optional (e.g. Person.Address can be null). 在 EF Core 5.0 中,可根据需要配置依赖项。In EF Core 5.0, dependents can be configured as required.

合理化 ToTable、ToQuery、ToView、FromSql 等Rationalize ToTable, ToQuery, ToView, FromSql, etc

开发人员负责人:@AndriySvyryd 和 @smitpatelLead developers: @AndriySvyryd and @smitpatel

通过 #17270 进行跟踪Tracked by #17270

T 恤大小:LT-shirt size: L

状态:完成Status: Done

在以前的版本中,我们在支持原始 SQL、无键类型和相关领域方面取得了进展。We have made progress in previous releases towards supporting raw SQL, keyless types, and related areas. 但是,在所有内容作为一个整体协同工作的方式上存在差距和不一致。However, there are both gaps and inconsistencies in the way everything works together as a whole. 5.0 的目标是修复这些问题,并为定义、迁移和使用不同类型的实体及其关联查询和数据库项目创造良好体验。The goal for 5.0 is to fix these and create a good experience for defining, migrating, and using different types of entities and their associated queries and database artifacts. 这也可能涉及到已编译查询 API 的更新。This may also involve updates to the compiled query API.

请注意,此项可能会导致某些应用程序级重大更改,因为我们当前拥有的某些功能过于宽松,以至于它可能很快导致人们陷入困境。Note that this item may result in some application-level breaking changes since some of the functionality we currently have is too permissive such that it can quickly lead people into pits of failure. 我们可能最终会阻止其中一些功能,并改为提供有关应执行的操作的指导。We will likely end up blocking some of this functionality together with guidance on what to do instead.

常规查询增强功能General query enhancements

开发人员负责人:@smitpatel 和 @maumarLead developers: @smitpatel and @maumar

通过 5.0 里程碑中使用 area-query 标记的问题进行跟踪Tracked by issues labeled with area-query in the 5.0 milestone

T 恤大小:XLT-shirt size: XL

状态:完成Status: Done

查询转换代码已针对 EF Core 3.0 进行了广泛重写。The query translation code was extensively rewritten for EF Core 3.0. 因此,查询代码一般处于更可靠的状态。The query code is generally in a much more robust state because of this. 对于 5.0,在支持 TPT 和 skip 导航属性所需的更改范围之外,我们未计划进行重大查询更改。For 5.0 we aren't planning on making major query changes, outside those needed to support TPT and skip navigation properties. 但是,仍然需要大量工作来修复 3.0 全面修改中遗留的一些技术债务。However, there is still significant work needed to fix some technical debt left over from the 3.0 overhaul. 我们还计划修复许多 bug 并实现少量的增强功能,以进一步改进总体查询体验。We also plan to fix many bugs and implement small enhancements to further improve the overall query experience.

迁移和部署体验Migrations and deployment experience

开发人员负责人:@bricelamLead developers: @bricelam

通过 #19587 进行跟踪Tracked by #19587

T 恤大小:LT-shirt size: L

状态:作用域/完成Status: Scoped/Done

范围问题:迁移捆绑功能已推迟到 EF Core 5.0 发布之后。Scoping: The migrations bundles feature has been deferred until after the EF Core 5.0 release. 但是,EF Core 5.0 中将包含与迁移相关的一些其他目标改进However, several other targeted improvements related to migrations will be included in EF Core 5.0

当前,许多开发人员在应用程序启动时迁移其数据库。Currently, many developers migrate their databases at application startup time. 这十分简单,但不建议这样做,因为:This is easy but is not recommended because:

  • 多个线程/进程/服务器可能会并发尝试迁移数据库Multiple threads/processes/servers may attempt to migrate the database concurrently
  • 发生这种情况时,应用程序可能会尝试访问不一致的状态Applications may try to access inconsistent state while this is happening
  • 通常,不应为应用程序执行授予修改架构的数据库权限Usually the database permissions to modify the schema should not be granted for application execution
  • 如果出现问题,则难以还原为干净状态It's hard to revert back to a clean state if something goes wrong

我们希望在这里提供更好的体验,从而可以轻松地在部署时迁移数据库。We want to deliver a better experience here that allows an easy way to migrate the database at deployment time. 这应该:This should:

  • 可在 Linux、Mac 和 Windows 上正常工作Work on Linux, Mac, and Windows
  • 在命令行上具有良好体验Be a good experience on the command line
  • 支持采用容器的方案Support scenarios with containers
  • 适用于常用的实际部署工具/流Work with commonly used real-world deployment tools/flows
  • 至少集成到 Visual Studio 中Integrate into at least Visual Studio

结果可能是在 EF Core 中进行许多小改进(例如,SQLite 上更好的迁移),并与其他团队一起进行指导和长期协作,以改进不仅限于 EF 的端到端体验。The result is likely to be many small improvements in EF Core (for example, better Migrations on SQLite), together with guidance and longer-term collaborations with other teams to improve end-to-end experiences that go beyond just EF.

EF Core 平台体验EF Core platforms experience

开发人员负责人:@roji 和 @bricelamLead developers: @roji and @bricelam

通过 #19588 进行跟踪Tracked by #19588

T 恤大小:LT-shirt size: L

状态:作用域/完成Status: Scope/Done

范围问题:为 Blazor、Xamarin、WinForms 和 WPF 发布了平台指南和示例。Scoping: Platform guidance and samples are published for Blazor, Xamarin, WinForms, and WPF. 现已计划为 EF Core 6.0 的发行进行 Xamarin 和其他 AOT/链接器工作。Xamarin and other AOT/linker work is now planned for EF Core 6.0.

我们提供了有关在类似传统 MVC 的 Web 应用程序中使用 EF Core 的良好指导。We have good guidance for using EF Core in traditional MVC-like web applications. 适用于其他平台和应用程序模型的指导缺失或过期。Guidance for other platforms and application models is either missing or out-of-date. 对于 EF Core 5.0,我们计划调查、改进和记录在以下方面使用 EF Core 的体验:For EF Core 5.0, we plan to investigate, improve, and document the experience of using EF Core with:

  • BlazorBlazor
  • Xamarin,包括使用 AOT/链接器情景Xamarin, including using the AOT/linker story
  • WinForms/WPF/WinUI,可能还有其他 U.I.WinForms/WPF/WinUI and possibly other U.I. 框架frameworks

这可能是在 EF Core 中进行许多小改进,并与其他团队一起进行指导和长期协作,以改进不仅限于 EF 的端到端体验。This is likely to be many small improvements in EF Core, together with guidance and longer-term collaborations with other teams to improve end-to-end experiences that go beyond just EF.

我们计划研究的特定领域有:Specific areas we plan to look at are:

  • 部署,包括使用 EF 工具(例如用于迁移)的体验Deployment, including the experience for using EF tooling such as for Migrations
  • 应用程序模型(包括 Xamarin 和 Blazor),可能还有其他模型Application models, including Xamarin and Blazor, and probably others
  • SQLite 体验,包括空间体验和表重新生成SQLite experiences, including the spatial experience and table rebuilds
  • AOT 和链接体验AOT and linking experiences
  • 诊断集成,包括性能计数器Diagnostics integration, including perf counters

性能Performance

开发人员负责人:@rojiLead developer: @roji

通过 5.0 里程碑中使用 area-perf 标记的问题进行跟踪Tracked by issues labeled with area-perf in the 5.0 milestone

T 恤大小:LT-shirt size: L

状态:作用域/完成Status: Scoped/Done

范围问题:Npgsql 提供程序的主要性能改进已完成。Scoping: Major performance improvements in the Npgsql provider are complete. 现已计划为 EF Core 6.0 的发行进行其他性能工作。Other performance work is now planned for EF Core 6.0.

对于 EF Core,我们计划改进性能基准套件,并对运行时进行定向性能改进。For EF Core, we plan to improve our suite of performance benchmarks and make directed performance improvements to the runtime. 此外,我们计划完成在 3.0 发布周期内进行原型设计的新 ADO.NET 批处理 API。In addition, we plan to complete the new ADO.NET batching API which was prototyped during the 3.0 release cycle. 同样在 ADO.NET 层,我们计划对 Npgsql 提供程序进行其他性能改进。Also at the ADO.NET layer, we plan additional performance improvements to the Npgsql provider.

作为此工作的一部分,我们还计划根据需要添加 ADO.NET/EF Core 性能计数器和其他诊断。As part of this work we also plan to add ADO.NET/EF Core performance counters and other diagnostics as appropriate.

体系结构/参与者文档Architectural/contributor documentation

文档管理人员主管:@ajcvickersLead documenter: @ajcvickers

通过 #1920 进行跟踪Tracked by #1920

T 恤大小:LT-shirt size: L

状态:剪切Status: Cut

这里的思路是使人们更容易了解 EF Core 的内部情况。The idea here is to make it easier to understand what is going on in the internals of EF Core. 这可能对于使用 EF Core 的任何人都十分有用,但主要动机是使外部人员更容易:This can be useful to anyone using EF Core, but the primary motivation is to make it easier for external people to:

  • 为 EF Core 代码做出贡献Contribute to the EF Core code
  • 创建数据库提供程序Create database providers
  • 构建其他扩展Build other extensions

更新:遗憾的是,该计划过于宏大。Update: Unfortunately, this plan was too ambitious. 我们仍相信这很重要,但遗憾的是,EF Core 5.0 未包含它。We still believe this is important, but unfortunately it won't land with EF Core 5.0.

Microsoft.Data.Sqlite 文档Microsoft.Data.Sqlite documentation

文档管理人员主管:@bricelamLead documenter: @bricelam

通过 #1675 进行跟踪Tracked by #1675

T 恤大小:MT-shirt size: M

状态:已完成。Status: Completed. 新文档在 Microsoft 文档站点上提供The new documentation is live on the Microsoft docs site.

EF 团队还拥有 Microsoft.Data.Sqlite ADO.NET 提供程序。The EF Team also owns the Microsoft.Data.Sqlite ADO.NET provider. 我们计划在 5.0 版本中完整记录此提供程序。We plan to fully document this provider as part of the 5.0 release.

常规文档General documentation

文档管理人员主管:@ajcvickersLead documenter: @ajcvickers

通过 5.0 里程碑的文档存储库中的问题进行跟踪Tracked by issues in the docs repo in the 5.0 milestone

T 恤大小:LT-shirt size: L

状态:正在进行Status: In-progress

我们已在针对 3.0 和 3.1 版本更新文档。We are already in the process of updating documentation for the 3.0 and 3.1 releases. 我们还在致力于:We are also working on:

  • 全面修改入门文档,使它们更易于理解/更易于遵循An overhaul of the getting started docs to make them more approachable/easier to follow
  • 重新组织文档,使内容更易于查找并添加交叉引用Reorganization of docs to make things easier to find and to add cross-references
  • 向现有文档添加更多详细信息和说明Adding more details and clarifications to existing docs
  • 更新示例并添加更多示例Updating the samples and adding more examples

修复 bugFixing bugs

通过 5.0 里程碑中使用 type-bug 标记的问题进行跟踪Tracked by issues labeled with type-bug in the 5.0 milestone

开发人员:@roji、@maumar、@bricelam、@smitpatel、@AndriySvyryd、@ajcvickersDevelopers: @roji, @maumar, @bricelam, @smitpatel, @AndriySvyryd, @ajcvickers

T 恤大小:LT-shirt size: L

状态:正在进行Status: In-progress

撰写本文时,我们已将 135 个 bug 会审为在 5.0 版本中进行修复(已修复了 62 个),但与上面的常规查询增强功能部分存在很大的重叠。At the time of writing, we have 135 bugs triaged to be fixed in the 5.0 release (with 62 already fixed), but there is significant overlap with the General query enhancements section above.

在 3.0 版本期间,传入率(最终成为里程碑工作的问题)大约为每月 23 个问题。The incoming rate (issues that end up as work in a milestone) was about 23 issues per month over the course of the 3.0 release. 并非所有这些问题都需要在 5.0 中进行修复。Not all of these will need to be fixed in 5.0. 作为大致估计,我们计划修复在 5.0 时间范围内修复其他 150 个问题。As a rough estimate we plan to fix an additional 150 issues in the 5.0 time frame.

小型增强功能Small enhancements

通过 5.0 里程碑中使用 type-enhancement 标记的问题进行跟踪Tracked by issues labeled with type-enhancement in the 5.0 milestone

开发人员:@roji、@maumar、@bricelam、@smitpatel、@AndriySvyryd、@ajcvickersDevelopers: @roji, @maumar, @bricelam, @smitpatel, @AndriySvyryd, @ajcvickers

T 恤大小:LT-shirt size: L

状态:完成Status: Done

除了上面概述的较大功能之外,我们还计划对 5.0 进行许多较小的改进,以修复“小问题”。In addition to the bigger features outlined above, we also have many smaller improvements scheduled for 5.0 to fix "paper-cuts". 请注意,上面概述的更一般主题也涵盖了其中许多增强功能。Note that many of these enhancements are also covered by the more general themes outlined above.

非计划Below-the-line

通过使用 consider-for-next-release 标记的问题进行跟踪Tracked by issues labeled with consider-for-next-release

这些是当前未针对 5.0 版本计划的 bug 修复和增强功能,但我们将根据以上工作的进度将它们视为延伸目标。These are bug fixes and enhancements that are not currently scheduled for the 5.0 release, but we will look at as stretch goals depending on the progress made on the work above.

此外,我们始终会在计划时考虑投票最多的问题In addition, we always consider the most voted issues when planning. 从版本中去除其中任何问题总是很痛苦的,但是我们确实需要针对所拥有的资源制定切合实际的计划。Cutting any of these issues from a release is always painful, but we do need a realistic plan for the resources we have.

建议Suggestions

你对计划的反馈非常重要。Your feedback on planning is important. 指示问题重要性的最佳方式是在 GitHub 上为该问题投票(竖起大拇指)。The best way to indicate the importance of an issue is to vote (thumbs-up) for that issue on GitHub. 然后,此数据将进入下一个版本的计划过程This data will then feed into the planning process for the next release.