c# - 带有 ASP.NET Core 3 的 Entity Framework 6.3

标签 c# asp.net-core entity-framework-6

如何将 Entity Framework 6.3 与 ASP .NET Core 3 一起使用?具体来说,我希望从现有数据库生成一个模型。除非我以完整的 .NET Framework 为目标,否则我似乎无法添加实体数据模型(但是,.NET Core 3 不支持 Entity Framework 6.3 吗?)

最佳答案

如果我对你的问题的理解正确,你想使用 .Net Core 和 Entity Framework 从你的数据库表生成模型。

您可以通过在您的项目中使用 Entity Framework Core 和工具包来做到这一点。

  dotnet add package Microsoft.EntityFrameworkCore.SqlServer
  dotnet add package Microsoft.EntityFrameworkCore.Design

还有 dotnet ef dbcontext scaffold

例子:

    dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models

根据设计师对 EF 6.3 的支持,我认为你运气不好:

这是 Microsoft 目前推荐的方法:

How to work with EDMX files in .NET Core projects On the tooling side, we plan to release an updated EF6 designer in an upcoming update of Visual Studio 2019 which will work with projects that target .NET Core (tracked in issue #883).

Until this new version of the designer is available, we recommend that you work with your EDMX files inside projects that target .NET Framework. You can then add the EDMX file and the generated classes for the entities and the DbContext to the .NET Core 3.0 or .NET Standard 2.1 project as linked files.

https://github.com/efcore/EdmxDotNetCoreSample/

关于c# - 带有 ASP.NET Core 3 的 Entity Framework 6.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58075341/

相关文章:

C#打开新窗体时,旧窗体必须停止

typescript - Visual Studio 2015 CTP 6 - 将 Typescript 输出合并到单个 .js 文件中

javascript - 如何从 Angular ngFor 中的方法中提取值

c# - EF6 不保存对相关属性的更改

c# - .NET显示不同的数据库变量但保存为ID?

entity-framework - 类型 'System.Data.Spatial.DbGeography' 必须是不可为 null 的值类型才能将其用作参数 'T'

c# - 使用 ASP.NET Identity 重置密码时 token 无效

c# - 将 CRC16 计算从 C 转换为 C#

c# - 使用正则表达式从字符串中检索数字

asp.net-core - 在发布时替换 asp.net core 中的 web.config vs 2017