Separate Migrations Project(Class Library) — Entity Framework Core

KANHAIYA TYAGI
May 20, 2021

You may want to store your migrations in a different project than the one containing your ApplicationDbContext. You can also use this strategy to maintain multiple sets of migrations, for example, one for development and another for release-to-release upgrades. I used Entity Framework core 5.0 and ASP.NET core Web Application 5.0

Steps

  1. Create a ASP.NET core web application, project name “Xaero”. Add another Class Library in same project name as “Xaero.DataLayer”
  2. Add a reference “Xaero.DataLayer” to “Xaero”.
  3. Move the migrations and model snapshot files to the class library.
  4. Configure the migrations assembly in “Xaero”. Goto ConfigureServices method in Startup.cs file
View of Startup.cs
Add connection string into appsetting.json file

5. GitHub link for project.

6. Thank you for reading.

“A clever person solves a problem.

A wise person AVOIDS it.”

--

--

KANHAIYA TYAGI

Engineer, GIS, .NET, JavaScript, jQuery, Azure, Angular