【发布时间】:2020-02-06 08:15:46
【问题描述】:
是否可以为模型/上下文/迁移提供一个通用代码库以使用来自 asp.net 核心应用程序 (3.1) 和 .net 框架应用程序 (4.6.1) 的相同 SQL DB?我的尝试失败了。除了创建两个项目之外没有其他解决方案,一个在 .net core 3.1 程序集中使用 EF 核心,一个在目标 4.6.1 中使用 EF6。
我尝试创建一个 .net 标准 2.0 项目(只有 EF 核心),我可以从两个应用程序中引用它,但这似乎不可能?使用迁移工具失败,因为.net standard 2.0只有一个“接口”?
dotnet ef migrations add InitialCreate
> Startup project 'TestStandard.csproj' targets framework
> '.NETStandard'. There is no runtime associated with this framework,
> and projects targeting it cannot be executed directly. To use the
> Entity Framework Core .NET Command-line Tools with this project, add
> an executable project targeting .NET Core or .NET Framework that
> references this project
【问题讨论】:
-
您在使用迁移工具时看到的具体问题/错误是什么?我在一个项目(netstandard2.1 库)和另一个项目(netcoreapp3.1)中有应用程序的工作项目
-
为纯粹用于事务的数据库创建第三个代码库。让它通过 api 发出数据模型。在您的其他 2 个应用中设置 API。
-
@Zze 这意味着关于数据模型的更改我必须更改 3 个项目?这与我的目标相反。
-
实际工作量差异很小,因为您可以将数据模型放在其他 2 个解决方案的共享 csproj 中。这样,对 EF 中数据模型的更改会自动进入预期的 api 结果。
标签: c# entity-framework asp.net-core entity-framework-core .net-standard