.net core EF使用

# EF 使用

## code first

1.repo 增加dbset
2.初始化数据
程序包管理控制台,选择默认项目Repo
PM>
Add-Migration Init  //其中Init是你的版本名称
update-database Init //更新数据库操作 init为版本名称

3.如果entity修改了
程序包管理控制台PM>
Add-Migration V20180725  
update-database V20180725

##  db first

### MySql

运行:Scaffold-DbContext -Connection "Server=localhost;Port=3306;Database=jinbi0725; User=test;Password=123456;" -Provider "Pomelo.EntityFrameworkCore.MySql" -outputDir "Base/EF" -Context "UDbContext"  -force -tables "user","gift" 

### MsSql

运行:Scaffold-DbContext -Connection "Server=localhost;User Id=root;Password=123456;Database=vanfj" -Provider "Microsoft.EntityFrameworkCore.SqlServer" -OutputDir "Models"

命令解析:
Scaffold-DbContext “数据库连接字符串” Microsoft.EntityFrameworkCore.SqlServer -OutputDir 输出的文件夹,如无此参将生成到项目根目录
如果只想生成某些表将使用Tables参数 如: -tables "user","gift"
如果可以覆盖文件加参数 -force
其他参数可输入 Scaffold-DbContext -? 查看帮助.

你可能感兴趣的:(c#)