如何将 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.
关于c# - 带有 ASP.NET Core 3 的 Entity Framework 6.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58075341/