数据库优先 - EF6 On Mono
Database first - EF6 On Mono
上下文:
我需要一个 "legacy" .Net 应用程序在我的本地机器上运行,它是一台 Macbook...(我们的大部分堆栈都是 dotnetcore),但这个特定的应用程序有点旧。
虽然我确实意识到启动一个 windows VM 并在其中构建它会容易得多,但我正在尝试构建项目(和 运行使用单声道)
到目前为止,我已经通过在 .csproj
中添加一些条件检查解决了一些问题,这使应用程序得以构建并且 运行...几乎没有,因为当我点击首先 API 检查数据库的连接性。
当前设置:
- Mono JIT 编译器版本 5.18.1.3
- .Net 目标 4.6.1
- Rider IDE(我也安装了 OSX 的 VS)
- EF6.1.3
项目结构如下:
Project.Data
- App.Config
- DataModel.edmx
Project.Api (which references the Project.Data)
- Web.Config
两者都包含以下连接字符串(为简洁起见缩进):
<add name="SomeEntities"
connectionString="
metadata=
res://*/DataModel.csdl|
res://*/DataModel.ssdl|
res://*/DataModel.msl;
provider=System.Data.SqlClient;
provider connection string=
"
data source=somedb;
initial catalog=some_catalog;
user id=some_id;
password=some_password;
App=EntityFramework;
"
"
providerName="System.Data.EntityClient" />
问题:
我认为发生的事情是常规构建任务不会从 .edmx
生成正确的文件,但是关于如何在我当前的环境中生成正确的文件......我开始考虑它不可能。
错误:
Unable to load the specified metadata resource.
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources
我看过各种关于修改连接字符串的帖子,结果各不相同,但从未导致应用程序正常运行。
更改为,metadata=res://*/;
结果:
Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied.
at System.Data.Entity.Core.EntityUtil.CheckArgumentEmpty[T]
更改为标准 SqlConnection 字符串:
System.Data.Entity.Infrastructure.UnintentionalCodeFirstException:
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection, then make sure that it is an EntityConnection and not some other type of DbConnection, and that you pass it to one of the base DbContext constructors that take a DbConnection. To learn more about Code First, Database First, and Model First see the Entity Framework documentation here: http://go.microsoft.com/fwlink/?LinkId=394715
问题:
这完全有可能吗,还是我应该恢复 windows 机器?
所以在浏览了一段时间的网络并询问了一些论坛和群组之后,我得出的结论是这可能是徒劳的,尤其是考虑到像 dotnetcore 这样的东西现在很普遍.
issue 的一位开发人员为 Mac 团队回答了有关 issue 的更多背景...
On Windows there are some Microsoft.Data.Entity MSBuild tasks. These
are used to generate the various .csdl, .ssdl, and .msl files at build
time from the .edmx file. If you look at the build output in Visual
Studio on Windows you should see something similar to:
Building target "EntityDeployEmbeddedResources" completely. Output
file "obj\Debug\edmsREsourcesToEmbed\Model.ssdl" does not exist. Using
"EntityDeploy" task from assembly
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Data.Entity.Build.Tasks.dll".
The Microsoft.Data.Entity.Build.Tasks.dll and the associated
Microsoft.Data.Entity.targets file do not exist for the Mac.
On the Mac the only workaround is to use Entity Framework Core which
is cross platform and not to use edmx files since these are not
supported.
因此选项是:
- dotnetcore 端口,或
- 得到一台windows机器
...对于这个遗留应用程序。而且由于我们正在以任何一种方式迁移到 dotnetcore...我相信现实的解决方案是优先将此特定项目移植到 dotnetcore。
由于现在可以使用具有更好的跨平台支持的新版本的 EF,因此升级 EF 可以解决该问题。 (从 6.2.0 升级到 6.4.4)
上下文:
我需要一个 "legacy" .Net 应用程序在我的本地机器上运行,它是一台 Macbook...(我们的大部分堆栈都是 dotnetcore),但这个特定的应用程序有点旧。
虽然我确实意识到启动一个 windows VM 并在其中构建它会容易得多,但我正在尝试构建项目(和 运行使用单声道)
到目前为止,我已经通过在 .csproj
中添加一些条件检查解决了一些问题,这使应用程序得以构建并且 运行...几乎没有,因为当我点击首先 API 检查数据库的连接性。
当前设置:
- Mono JIT 编译器版本 5.18.1.3
- .Net 目标 4.6.1
- Rider IDE(我也安装了 OSX 的 VS)
- EF6.1.3
项目结构如下:
Project.Data
- App.Config
- DataModel.edmx
Project.Api (which references the Project.Data)
- Web.Config
两者都包含以下连接字符串(为简洁起见缩进):
<add name="SomeEntities"
connectionString="
metadata=
res://*/DataModel.csdl|
res://*/DataModel.ssdl|
res://*/DataModel.msl;
provider=System.Data.SqlClient;
provider connection string=
"
data source=somedb;
initial catalog=some_catalog;
user id=some_id;
password=some_password;
App=EntityFramework;
"
"
providerName="System.Data.EntityClient" />
问题:
我认为发生的事情是常规构建任务不会从 .edmx
生成正确的文件,但是关于如何在我当前的环境中生成正确的文件......我开始考虑它不可能。
错误:
Unable to load the specified metadata resource.
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources
我看过各种关于修改连接字符串的帖子,结果各不相同,但从未导致应用程序正常运行。
更改为,metadata=res://*/;
结果:
Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied.
at System.Data.Entity.Core.EntityUtil.CheckArgumentEmpty[T]
更改为标准 SqlConnection 字符串:
System.Data.Entity.Infrastructure.UnintentionalCodeFirstException:
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection, then make sure that it is an EntityConnection and not some other type of DbConnection, and that you pass it to one of the base DbContext constructors that take a DbConnection. To learn more about Code First, Database First, and Model First see the Entity Framework documentation here: http://go.microsoft.com/fwlink/?LinkId=394715
问题:
这完全有可能吗,还是我应该恢复 windows 机器?
所以在浏览了一段时间的网络并询问了一些论坛和群组之后,我得出的结论是这可能是徒劳的,尤其是考虑到像 dotnetcore 这样的东西现在很普遍.
issue 的一位开发人员为 Mac 团队回答了有关 issue 的更多背景...
On Windows there are some Microsoft.Data.Entity MSBuild tasks. These are used to generate the various .csdl, .ssdl, and .msl files at build time from the .edmx file. If you look at the build output in Visual Studio on Windows you should see something similar to:
Building target "EntityDeployEmbeddedResources" completely. Output file "obj\Debug\edmsREsourcesToEmbed\Model.ssdl" does not exist. Using "EntityDeploy" task from assembly "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Data.Entity.Build.Tasks.dll". The Microsoft.Data.Entity.Build.Tasks.dll and the associated Microsoft.Data.Entity.targets file do not exist for the Mac.
On the Mac the only workaround is to use Entity Framework Core which is cross platform and not to use edmx files since these are not supported.
因此选项是:
- dotnetcore 端口,或
- 得到一台windows机器
...对于这个遗留应用程序。而且由于我们正在以任何一种方式迁移到 dotnetcore...我相信现实的解决方案是优先将此特定项目移植到 dotnetcore。
由于现在可以使用具有更好的跨平台支持的新版本的 EF,因此升级 EF 可以解决该问题。 (从 6.2.0 升级到 6.4.4)