对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

升级提供商版本

在本节中,您可以确定将提供商升级到新版本时必须对应用程序进行的基本更改。

升级前,请执行以下操作:

  • Ensure the new version is compatible with the MongoDB Server version your application connects to and the .NET version your application runs on. See the Compatibility page for this information.

  • 在“重大更改”部分中,解决应用程序正在使用的提供商程序的当前版本与计划升级版本之间发生的任何重大更改。

破坏性变更 (breaking change)是对从特定版本的提供商开始的约定或行为的修改。 如果在升级提供商之前未解决此问题,此类更改可能会导致应用程序无法正常工作。

本节中的重大更改按引入它们的提供商版本进行分类。 升级提供商版本时,请解决当前版本和升级版本之间的所有重大更改。 示例,如果您要将提供商从 v 8.0升级到 v 8.5 ,请解决v 8.0之后版本的所有重大更改, 包括 v 8.5下列出的任何内容。

EF Core 提供程序的 9.0.0 版本包含与 EF Core 提供程序的 8.3.0 版本相同的重大更改。

For more information about the breaking changes in version 9.0.0 and how to address them, see the Version 8.3.0 Breaking Changes section.

EF Core 提供程序的 8.3.0 版本引入了一项破坏性变更 (breaking change),该更改纠正对使用备用BSON表示形式配置的可空属性的处理。在以前的版本中,不会应用由 [BsonRepresentation] 属性或 HasBsonRepresentation() Fluent API设立的配置。

您可以通过以下两种方式之一解决动作差异:

  • 如果使用替代BSON表示形式并不重要,请在应用程序启动之前从应用程序中删除配置。

  • 或者,您可以将受影响的元素更新为新的表示形式。作为升级进程的一部分,请对每个受影响的MongoDB集合使用 updateMany 方法,通过 $convert 操作将任何受影响的可为 null 的属性或元素重写为所需的BSON表示形式。

    示例,您可以将名为 people 的集合中的 dateOfBirth 元素从BSON date 转换为BSON int,如以下代码所示:

    db.people.updateMany(
    { dateOfBirth: {$type: "date" } },
    [
    { $set: {
    dateOfBirth:
    { $convert:
    { input: "$dateOfBirth",
    to: "int",
    onNull: null
    }
    }
    }
    }
    ]
    )

Version 8.2.0 of the EF Core Provider does not directly introduce any breaking changes. However, the underlying .NET/C# Driver introduces many potentially breaking changes in the v3.0 release, which might affect your application. To learn more about the breaking changes in v3.0 of the .NET/C# Driver, see the Upgrade to Version 3.0 guide in the .NET/C# Driver documentation.

  • 更新了 EF Core 提供程序以运行所有更改作为MongoDB事务运行。 如果您的应用程序使用 v 5.0之前版本的MongoDB Server , 或不在副本集运行,则必须对应用程序进行以下更改:

    • 如果您的应用程序配置为适用于 v 5.0之前的MongoDB Server版本, 您必须升级到MongoDB Server v 5.0或更高版本。

    • If your application runs on a standalone server, you must reconfigure your standalone server to a single-instance replica set. To learn more about how to reconfigure your standalone server, see Convert a Standalone Self-Managed mongod to a Replica Set in the MongoDB Server manual.

    • 如果您的应用程序在容器环境中运行,请切换到单实例副本集容器(如果有)。

    为避免事务期间出现快照问题,请在应用程序启动期间调用EnsureCreated()或EnsureCreatedAsync()方法,而不是隐式创建集合或数据库。

    注意

    如果应用程序在共享集群上运行,则调用 EnsureCreated()或EnsureCreatedAsync() 方法会引发错误。在免费和共享集群上运行的应用程序不应调用这些方法。

    如果您不想确保事务的乐观并发性,可以在应用程序设置期间通过在 DbContext 子类上设置 Database.AutoTransactionBehavior = AutoTrasactionBehavior.Never 来禁用自动事务。

  • 将默认GUID存储格式从CSharpLegacy二进制格式更改为Standard格式。 如果数据库包含非Standard格式的现有 GUID,我们建议将其转换为Standard格式。

  • CamelCaseElementNameConvention根据属性名称而不是类名称转换所属实体的大小写。 如果您的应用程序使用CamelCaseElementNameConvention ,数据大小写可能会更改。

有关此版本中重大更改的更多信息,请参阅Github上提供商存储库的重大更改部分。

给本页内容打分

在此页面上