更改实体框架核心代码第一次迁移名称格式

Ali*_*eza 3 entity-framework-core entity-framework-migrations

ef core 使用系统日历格式生成迁移名称。

Windows 上公历的标准迁移名称示例:

20190206144020_MIGRATION-NAME
Run Code Online (Sandbox Code Playgroud)

但是,如果 Windows 的日期格式不是公历,例如波斯历,则 ef 核心迁移名称会生成如下内容:

13971114210223_MIGRATION-NAME
Run Code Online (Sandbox Code Playgroud)

在团队项目中,我们不能同时使用这两种格式,因为它会改变迁移的顺序。

有没有办法在不更改 Windows 日历格式或手动重命名迁移的情况下解决该问题?

版本:EF 核心 2.2

Iva*_*oev 5

这简直是在一个错误MigrationsIdGenerator最新此时EF核心2.2.4类-在最后一行GenerateId方法:

return timestamp.ToString(Format) + "_" + name;
Run Code Online (Sandbox Code Playgroud)

他们只是忘记传递CultureInfo.InvariantCultureDateTime.Format方法。

已经在当前代码中修复(我相信对于 EF Core 3.0),所以你要么等待它,要么将当前代码复制/粘贴到你的项目中(重命名类让 say FixedMigrationsIdGenerator),然后在你的DbContext派生类中,覆盖OnConfiguring和添加以下内容(带有必要的usings):

optionsBuilder.ReplaceService<IMigrationsIdGenerator, FixedMigrationsIdGenerator>();
Run Code Online (Sandbox Code Playgroud)