首先安装EF的两个必要的包
> dotnet add package Microsoft.EntityFrameworkCore.SqlServer
> dotnet add package Microsoft.EntityFrameworkCore.Design
在vs下运行命令Scaffold-DbContext "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TestDB1;Data Source=SERVER2016;uid=sa;pwd=abc123#" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model -Context "AdventureContext" -DataAnnotations
也可以选择table, -Tables "Pub_InternalControlDes","Pub_InternalControlMap"
生成model后把
protected override void OnModelCreating(ModelBuilder modelBuilder) { }
里的都删掉,然后运行命令add-migration test;
udapte database,
把migration里面的up和down的方法都去掉,就完成了