Open Alice52 opened 4 years ago
create sql in DataBase, and use follow command to generate code
dotnet ef dbcontext scaffold "Server=T0xx-111\SQLEXPRESS;Database=DATABASE_NAME;User Id=sa; Password=sa" Microsoft.EntityFrameworkCore.SqlServer -f -t TABLE_NAME1 -t TABLE_NAME2 --output-dir Models --context-dir Db --context CustomContext --verbose
copy and refine code
add follow code to point out datasource in xxDbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer("Server=192.168.111.xxx;Database=DATABASE_Name;User Id=sa; Password=sa"); }
open TableManagement.DataAccess project and run the follow command to generate Migrations and DB
dotnet ef migrations add MIGRATION_NAME dotnet ef database update # this will generate sql dotnet ef migrations script -o Custom_Directory
when we execute migration add command, it will do the follow jobs
migration add
when we execute database update command, it will do the follow jobs
database update
Usage of Migrations
create sql in DataBase, and use follow command to generate code
copy and refine code
add follow code to point out datasource in xxDbContext
open TableManagement.DataAccess project and run the follow command to generate Migrations and DB
explain
when we execute
migration add
command, it will do the follow jobswhen we execute
database update
command, it will do the follow jobsreference