- 创建一个Console程序
- 引用如下Nuget包
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
</ItemGroup>
- 在程序包管理器控制台运行如下命令:
scaffold-dbcontext ConnectionString Microsoft.EntityFrameworkCore.SqlServer
示例代码如下:
scaffold-dbcontext "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MyTest;Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer
- 把生成的context和对应的Model移动到真实项目中去。