efcore6反向工程

依赖:

命令行:

Scaffold-DbContext 'Data Source=IP地址;Initial Catalog=数据库名称;uid=账号;pwd=密码' Microsoft.EntityFrameworkCore.SqlServer -ContextDir Data -OutputDir Models -Tables 表名 -DataAnnotations

Program.cs添加

//添加EFCORE上下文
builder.Services.AddDbContext<HyDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("HyDB"))
);

//配置连接字符串

{
  "ConnectionStrings": {
    "HyDB": "Data Source=IP地址;Initial Catalog=数据库名;uid=账号;pwd=密码"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}
posted @ 2022-06-09 15:54  星落森河  阅读(85)  评论(0)    收藏  举报