数据库优先-EF6 on Mono [英] Database first - EF6 On Mono

查看:72
本文介绍了数据库优先-EF6 on Mono的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:

我需要在运行Macbook的本地计算机上运行一个旧版" .Net应用程序(我们的堆栈大多数是dotnetcore),但是该特定应用程序有些旧.

I need to get a "legacy" .Net application working on my local machine which is a Macbook... (most of our stack is dotnetcore), but this specific application is a little older.

虽然我确实意识到,只需启动Windows VM并在其中构建它会容易得多,但我正在努力建立项目(并使用MONO运行)

While I do realize it would be MUCH easier to probably just spin up a windows VM and build it in there, I'm taking a stab at getting the project building (and running using MONO)

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

So far I've resolved a few issues by adding some conditional checks in the .csproj, which got the application building and running... barely, as it dies when I hit the first API that checks the db for connectivity.

当前设置:

  • 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

两者都包含以下连接字符串(为简洁起见缩进):

Both contain the following connection string (indented for brevity):

<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生成正确的文件,但是关于如何在当前环境中执行此操作……我开始认为这是不可能的.

I think whats happening is that the regular build task DOES NOT generate the correct files from the .edmx, but as to how to do that on my current env... I'm starting to think its impossible.

错误:

Unable to load the specified metadata resource.
  at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources

我见过很多有关修改连接字符串的文章,所有文章都有各种各样的结果,但从未使应用程序正常运行.

I've seen various posts about modifying the connection string, all with various results, but never resulting in a functioning application.

更改为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字符串:

Changing to a standard SqlConnection string:

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

Is this at all possible, or should I just revert getting a windows machine?

推荐答案

因此,在浏览了一段时间并询问了一些论坛和论坛之后,我得出的结论是,这可能是徒劳的努力,尤其是考虑到如今像dotnetcore这样的事情已经司空见惯.

So after traversing the web for a while, and asking on a few of the forums and groups, I've come to the conclusion that this might be a futile effort, especially considering that things like dotnetcore are commonplace these days.

问题上的更多上下文由一位开发者回答Mac团队的VS Code ...

Some more context on the issue answered by one of the devs on the VS Code for Mac team...

在Windows上,有一些Microsoft.Data.Entity MSBuild任务.这些 用于在生成时生成各种.csdl,.ssdl和.msl文件 .edmx文件中的时间.如果您在Visual中查看生成输出 Windows上的Studio,您应该会看到类似以下内容的内容:

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:

完全构建目标"EntityDeployEmbeddedResources".输出 文件"obj \ Debug \ edmsREsourcesToEmbed \ Model.ssdl"不存在.使用 程序集中的"EntityDeploy"任务 "C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Microsoft.Data.Entity.Build.Tasks.dll". Microsoft.Data.Entity.Build.Tasks.dll及其关联 对于Mac,Microsoft.Data.Entity.targets文件不存在.

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.

在Mac上,唯一的解决方法是使用Entity Framework Core 是跨平台的并且不使用edmx文件,因为这些不是 支持.

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.

...for this legacy app. And since we're migrating to dotnetcore either way... I believe the realistic solution is to prioritise porting of this specific item to dotnetcore.

这篇关于数据库优先-EF6 on Mono的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆