EF Core 3.1 是否支持 DB First 方法?

编程入门 行业动态 更新时间:2024-10-09 20:24:20
本文介绍了EF Core 3.1 是否支持 DB First 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们正在将 ASP.NET MVC 4.x 应用程序移植到 ASP.NET Core 3.1.当前应用程序使用 EF 6.x DB 第一种方法.作为此次迁移的一部分,我们将使用 EF Core 3.1 作为当前 EF 6.x 的替代方案.所以问题是:

We are porting an ASP.NET MVC 4.x application to ASP.NET Core 3.1. The current application is using EF 6.x DB first approach. As a part of this migration we are going to use EF Core 3.1 as an alternative to the current EF 6.x. So the question is:

EF Core 3.1 是否支持 DB First 方法?

如果没有,有什么选择?我们是否只剩下代码优先的方法?

If not, what are the options? Are we left with only code first approach?

感谢您的帮助.

推荐答案

是的.从 .NET Core 1.0 到现在,它都支持 DB First Approach.你需要从nugets下载4个

Yes. It supports DB First Approach since .NET Core 1.0 until now. You need to download 4 from nugets

  • EntityFrameworkCore

  • EntityFrameworkCore

    EntityFrameworkCore.Design

    EntityFrameworkCore.Design

    EntityFrameworkCore.Tools

    EntityFrameworkCore.Tools

    EntityFrameworkCore.SqlServer

    EntityFrameworkCore.SqlServer

    打开工具>NuGet 包管理器包管理器控制台.并在控制台中输入以下内容.

    Open Tools > NuGet Package Manager > Package Manager Console. And enter this below in console.

    默认:

    Scaffold-DbContext "Server=yourserveraddress;Database=yourdatabase;user id=youruser;password=yourpassword;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context "YourOwnContext"

    看到您对Scaffold-DbContext 仅创建代码优先模型"的评论.不,Scaffold-DbContext 是数据库优先的方法.

    Saw your comment about "Scaffold-DbContext only creates a Code First model". No, Scaffold-DbContext is Database-First approach.

    "创建实体&现有数据库的上下文类称为数据库优先方法."

    "Creating entity & context classes for an existing database is called Database-First approach."

    已编辑

    如果你在数据库中有新的更新并且想要更新 dbcontext,只需在末尾添加 -f.它将更新并覆盖您所有的 dbcontext 和模型类.

    If you have new update in database and want to update dbcontext, just add -f at end. It will update and overwrite all your dbcontext and model classes.

    Scaffold-DbContext "Server=yourserveraddress;Database=yourdatabase;user id=youruser;password=yourpassword;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context "YourOwnContext" -f

    如果要在model类中添加一些数据注解如[Column]等,可以添加-DataAnnotations

    If you want to add some data annotations such as [Column], etc in model class, can add -DataAnnotations

    Scaffold-DbContext "Server=yourserveraddress;Database=yourdatabase;user id=youruser;password=yourpassword;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context "YourOwnContext" -DataAnnotations -f
  • 更多推荐

    EF Core 3.1 是否支持 DB First 方法?

    本文发布于:2023-11-15 06:28:07,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1591963.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:方法   Core   EF   DB

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!