Adding Database Migrations for Entity Framework Core
Adding Database Migrations for Entity Framework Core with TD Web API
Hỗ trợ các DB Providers sau:
- MSSQL
- MySQL
- PostgreSQL
- Oracle
Cấu hình trong src/Host/Configurations/database.json.
Các loại database được hỗ trợ
- MSSQL - mssql
- MySQL - mysql
- PostgreSQL - postgresql
- Oracle - oracle
TD Web API gồm các EF Core DB Context sau:
- ApplicationDbContext - Entities của ứng dụng được tham chiếu ở đây
- TenantDbContext - Liên quan tới Finbuckle’s Multitenancy.
Sau khi đã thêm các entities vào Domain project và thêm cấu hình phù hợp trong TD.WebApi.Infrastructure.Persistence.Configuration và TD.WebApi.Infrastructure.Persistence.Context, cách để tạo migrations:
- Mở command terminal trên thư mục của
Host Projectvà dùng lệnh:
dotnet ef migrations add <CommitMessage> --project .././Migrators/Migrators.<DBProvider>/ --context ApplicationDbContext -o Migrations/Application
Trong đó
<CommitMessage>mô tả Migration<DBProvider>Database Provider (MSSQL,MySQL,OraclehoặcPostgreSQL)
Ví dụ Tạo migrations cho ApplicationDbContext,
dotnet ef migrations add AddedMenuEntity --project .././Migrators/Migrators.MSSQL/ --context ApplicationDbContext -o Migrations/Application
Tạo migrations cho TenantDbContext,
dotnet ef migrations add ModifiedTenantTable --project .././Migrators/Migrators.MSSQL/ --context TenantDbContext -o Migrations/Tenant
Like TDWebAPI? ❤️
Here is what you can do to show your support!
Buy me a Coffee ☕