【发布时间】:2016-12-07 14:55:28
【问题描述】:
我有一个在 .NET Framework 4.6.1 中运行的 EntityFramework 6 作为项目的 DAL。在其他 .NET Framework 项目的解决方案中运行良好。现在我要使用引用到我的 ASP.NET Core WebApi 的相同 DAL 项目(使用 .NET Framework 4.6.1),但它不起作用。异常说:
在应用程序配置文件中找不到名为“MyEntities”的连接字符串。
.NET Core 项目没有 web.config 文件,所以 EF6 如何将我的 Core 项目中的 appsettings.json 中的设置传递给引用的 DAL 项目?
我找到了一些让 EF6 在 .NET Core 项目中运行的示例(例如 https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6),但这对我没有帮助。我想这是因为 dbcontext 是在 DAL 项目中创建的。
appsettings.json
"ConnectionStrings": {
"MyEntities": "<my connectionString>"
},
项目.json
"dependencies": {
"EntityFramework": "6.1.3",
...
},
...
"frameworks": {
"net461": {
"dependencies": {
"DAL": {
"target": "project"
}
},
"imports": "dnxcore50"
}
},
【问题讨论】:
标签: entity-framework-6 .net-core