How to create multiple dbcontext in entity framework

Creating Multiple DbContext in EntityFramework

Is it possible to have multiple dbcontext?

Yes, we can create multiple DbContext classes in EF, which you can see below.

Syntax:

Enable-Migrations -ContextTypeName<DbContext-Name-with-Namespaces-MigrationsDirectory:<Migrations-Directory-Name>

Add-Migration -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces<Migrations-Name>

Update-Database -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces-Verbose

Sample:

Enable-migrations -ContextTypeName Migrations.DbContexts.Configuration -MigrationsDirectory:DbContexts

Add-Migration -configuration Migrations.DbContexts.Configuration

Update-Database -configuration Migrations.DbContexts.Configuration -Verbose

Leave a Reply