.NET
Applying Migration using Different DBContext
In case you are using several DbContext classes in Entity Framework Core, at that time, you may have to create migrations for different contexts individually. This helps in making a right check against each context’s schema into each respective database.
Here’s how to apply migrations for different DbContexts:
1. For adding migration
In Visual Studio > Package Manager Console
Add-Migration InitialCreate -Context AppDbContext
Add-Migration AuditLogCreate -Context AuditDbContext
Using .NET CLI
dotnet ef database update --context AppDbContext
dotnet ef database update --context AuditDbContext
2. For applying migrations
In Visual Studio > Package Manager Console
Update-Database -Context AppDbContext
Update-Database -Context AuditDbContext
Using .NET CLI
dotnet ef database update --context AppDbContext
dotnet ef database update --context AuditDbContext
By following these steps you are able to manage and apply migrations for any number of DbContext classes in project to Entity Framework Core at a different section of your application’s data model.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our .Net Expertise.
Comment