数据库优先-EF6 on Mono

时间:2019-04-05 09:48:49

标签: .net entity-framework msbuild mono

上下文:

我需要在运行Macbook的本地计算机上运行一个“旧版” .Net应用程序(我们的堆栈大部分是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=
  &quot;
    data source=somedb;
    initial catalog=some_catalog;
    user id=some_id;
    password=some_password;
    App=EntityFramework;
  &quot;
" 

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机器?

2 个答案:

答案 0 :(得分:0)

因此,在浏览了一段时间并询问了一些论坛和小组之后,我得出的结论是这可能是徒劳的,特别是考虑到如今像dotnetcore这样的事情已经司空见惯。 / p>

issue上的更多内容由VS Code for Mac团队的一名开发人员回答...

因此,这些选项是:

  • 连接到dotnetcore或
  • 获取Windows计算机

...此旧版应用程序。而且由于我们都以两种方式迁移到dotnetcore ...我相信现实的解决方案是优先考虑将此特定项目移植到dotnetcore。

答案 1 :(得分:0)

由于现在提供了具有更好跨平台支持的较新版本的 EF,升级 EF 可以解决该问题。 (从 6.2 升级到 6.4)