数据库优先 - EF6 On Mono

问题描述 投票:0回答:1

语境:

我需要在我的本地机器上运行一个“遗留”.Net应用程序,这是一个Macbook ...(我们的大多数堆栈是dotnetcore),但这个特定的应用程序有点旧。

虽然我确实意识到可能只是简单地启动一个Windows VM并在那里构建它,但我正在努力获得项目构建(并使用MONO运行)

到目前为止,我已经通过在.csproj中添加一些条件检查解决了一些问题,这使得应用程序构建并运行...几乎没有,因为当我点击第一个检查数据库连接的API时它就死了。

当前设置:

  • Mono JIT编译器版本5.18.1.3
  • .Net目标4.6.1
  • Rider IDE(我也安装了OS for OSX)
  • EF6.1.x

该项目的结构如下:

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

.net entity-framework msbuild mono
1个回答
1
投票

因此,在遍历网络一段时间,并询问一些论坛和小组之后,我得出的结论是,这可能是徒劳的,特别是考虑到像dotnetcore这样的东西现在很常见。

issue上的更多上下文由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。

© www.soinside.com 2019 - 2024. All rights reserved.