简体   繁体   English

如何使用.NET Standard和Entity Framework Core为现有数据库创建Entity Framework edmx文件?

[英]How to create an Entity Framework edmx file for an existing database with .NET Standard and Entity Framework Core?

In the past, I've been using .NET Framework 4.6 with Entity Framework 6 to generate an edmx file and the associated model files. 过去,我一直使用.NET Framework 4.6和Entity Framework 6生成edmx文件和关联的模型文件。 For one of my projects, I'd like to switch to ASP.NET Core MVC as front end and, therefore, want to change my DAL from .NET Framework 4.6 and EF 6 to .NET Standard 2. 对于我的一个项目,我想切换到ASP.NET Core MVC作为前端,因此,想要将我的DAL从.NET Framework 4.6和EF 6更改为.NET Standard 2。

Since the project files were initially created with VS 2012, they still use the old syntax and I somehow can't change the target framework via Visual Studio itself. 由于项目文件最初是使用VS 2012创建的,因此它们仍然使用旧语法,因此我无法以某种方式通过Visual Studio本身更改目标框架。 I've read that is probably easier to just recreate the project with Visual Studio 2017 and target .NET Standard 2 and just step-by-step insert the old code. 我已经读过,用Visual Studio 2017和目标.NET Standard 2重新创建项目,并逐步插入旧代码,可能会更容易。 The first thing that I want to recreate is my Entity Framework mapping with a DBContext. 我要重新创建的第一件事是使用DBContext映射实体框架。 So far, I've added some EF Core dependencies from NuGet, but I fail to create an edmx file that is comparable to what I'm used to from .NET Framework 4.6. 到目前为止,我已经从NuGet添加了一些EF Core依赖关系,但是我无法创建一个与我从.NET Framework 4.6所使用的文件相当的edmx文件。 Visual Studio does not seem to offer a specific wizard for that in 'add new file'. Visual Studio似乎没有在“添加新文件”中提供特定的向导。

What am I missing here? 我在这里想念什么? So far, I've checked some previous Stackoverflow posts (such as Trying to set-up Entity Framework core in .Net Standard project ) and multiple Udemy courses, but I still don't understand how I can use an equivalent of EF 6 (eg, an edmx file) in .NET Standard. 到目前为止,我已经检查了一些以前的Stackoverflow帖子(例如, 尝试在.Net Standard项目中设置Entity Framework核心 )和多个Udemy课程,但是我仍然不明白如何使用等效的EF 6( NET标准中的一个edmx文件)。

Per Microsoft: 每个Microsoft:

"EF Core does not support the EDMX file format for models. The best option to port these models, is to generate a new code-based model from the database for your application." “ EF Core不支持模型的EDMX文件格式。移植这些模型的最佳选择是从数据库中为您的应用程序生成基于代码的新模型。”

https://docs.microsoft.com/en-us/ef/efcore-and-ef6/porting/port-edmx https://docs.microsoft.com/zh-CN/ef/efcore-and-ef6/porting/port-edmx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM