gpt4 book ai didi

entity-framework - HasData 的数据播种不适用于 Visual Studio for Mac

转载 作者:行者123 更新时间:2023-12-05 07:33:05 26 4
gpt4 key购买 nike

我在 Visual Studio for MacOS 中遇到一些奇怪的行为。我最近安装了 .NET Core 2.1 SDK,然后将项目从 2.0 升级到 2.1。我想尝试新的数据播种功能,它让我们可以通过覆盖 OnModelCreating 方法将数据播种到实体中。

modelBuilder.Entity<Role>().HasData(
new Role { ID = 1, Name = "Administrator", RoleType = 0 },
new Role { ID = 2, Name = "Application User", RoleType = 0 });

最初,这将构建。然后我打开命令行并输入命令:

dotnet ef migration add v001

结果是“构建失败”。然后当我进入 VS 并构建时,它失败了。我已经重新启动 VS 并且可以一遍又一遍地重复这个。最初,项目构建没有错误。然后只有在尝试添加 EF 迁移后,才会出现构建错误。代码完成确实显示了 HasData 方法,我似乎正确地使用了它。我怀疑我在这里遇到了一个工具错误,感谢任何关于如何解决这个问题的建议。

最佳答案

问题是我没有遵循从 .NET Core 2.0 迁移到 2.1 时所需的迁移步骤:

Replace the version specified "Microsoft.AspNetCore.All" package reference with the versionless "Microsoft.AspNetCore.App" package reference. You may need to add dependencies that were removed from "Microsoft.AspNetCore.All"

这是记录在这里:

https://learn.microsoft.com/en-us/aspnet/core/migration/20_21?view=aspnetcore-2.1

关于entity-framework - HasData 的数据播种不适用于 Visual Studio for Mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50822964/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com