.net - 数据库优先 - Mono 上的 EF6
问题描述
语境:
我需要在我的本地机器上运行一个“旧版”.Net 应用程序,它是一台 Macbook ......(我们的大部分堆栈都是 dotnetcore),但这个特定的应用程序有点旧。
虽然我确实意识到启动 Windows VM 并在其中构建它会容易得多,但我正在努力构建项目(并使用 MONO 运行)
到目前为止,我已经通过在 中添加一些条件检查解决了一些问题.csproj
,这使得应用程序构建和运行......几乎没有,因为当我点击第一个检查数据库连接的 API 时它就死了。
当前设置:
- Mono JIT 编译器版本 5.18.1.3
- .Net 目标 4.6.1
- Rider IDE(我也安装了 VS for OSX)
- 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 之类的东西已经司空见惯。
VS Code for Mac 团队的一位开发人员回答了有关该问题的更多背景信息...
在 Windows 上,有一些 Microsoft.Data.Entity MSBuild 任务。这些用于在构建时从 .edmx 文件生成各种 .csdl、.ssdl 和 .msl 文件。如果您在 Windows 上的 Visual Studio 中查看构建输出,您应该会看到类似于以下内容的内容:
完全构建目标“EntityDeployEmbeddedResources”。输出文件“obj\Debug\edmsREsourcesToEmbed\Model.ssdl”不存在。使用程序集“C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Data.Entity.Build.Tasks.dll”中的“EntityDeploy”任务。Mac 不存在 Microsoft.Data.Entity.Build.Tasks.dll 和关联的 Microsoft.Data.Entity.targets 文件。
在 Mac 上,唯一的解决方法是使用跨平台的 Entity Framework Core,而不是使用 edmx 文件,因为这些文件不受支持。
因此选项是:
- 端口到 dotnetcore,或
- 获得一台windows机器
...对于这个旧版应用程序。而且由于我们正在以任何一种方式迁移到 dotnetcore... 我相信现实的解决方案是优先将此特定项目移植到 dotnetcore。
推荐阅读
- c++ - 将包含数字的数组作为参数传递 c++
- ios - iOS / Swift无法将文件写入将文件路径视为目录路径
- php - 使用 PHP 连接到 vCenter REST API
- r - R - 在没有替换的情况下对时间序列中的连续日期序列进行采样?
- typescript - 打字稿条件验证取决于字段可空性
- java - 在 Apache POI 中创建 XSSFWorkbook 时出现 OutOfMemoryError
- java - 是否可以在 JButton 中禁用文本截断?
- amazon-web-services - 将 java 应用程序与 aws 上的 rds 连接
- git - git clone 致命:远程意外挂断 git 2.17 存储库与 git 1.7 客户端
- asp.net-mvc - 记录 .net 核心应用程序的最佳实践