数据库优先 - Mono 上的 EF6

Database first - EF6 On Mono(数据库优先 - Mono 上的 EF6)

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

问题描述

Context:

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.

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)

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.

Current Setup:

  • Mono JIT compiler version 5.18.1.3
  • .Net Target 4.6.1
  • Rider IDE (I have VS for OSX Installed as well)
  • EF6.1.3

The project is structured as such:

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" />

Problem:

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.

Error:

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.

Changing to, metadata=res://*/; results in:

Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied. 
  at System.Data.Entity.Core.EntityUtil.CheckArgumentEmpty[T]

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

Question:

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

解决方案

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.

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

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 "objDebugedmsREsourcesToEmbedModel.ssdl" does not exist. Using "EntityDeploy" task from assembly "C:WindowsMicrosoft.NETFrameworkv4.0.30319Microsoft.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.

Thus the options are:

  • Port to dotnetcore, or
  • Get a windows machine

...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.

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

本文标题为:数据库优先 - Mono 上的 EF6

基础教程推荐