How to do migration using evolve in asp net core with nhibernate


ASP.NET is a popular programming language used for building web applications. In this article, we will explore how to perform using Evolve in ASP.NET Core with NHibernate.

What is Evolve?

Evolve is a migration tool that helps developers manage database schema changes in a controlled and automated way. It provides a simple and intuitive way to version and apply database schema changes.

Setting up NHibernate in ASP.NET Core

Before we can start using Evolve for database migration, we need to set up NHibernate in our ASP.NET Core project. Here's a step-by-step guide:

  1. Create a new ASP.NET Core project or open an existing one.
  2. Add the necessary NuGet packages for NHibernate and its dependencies.
  3. Create a configuration file for NHibernate, typically named “hibernate.cfg.xml”. This file contains the database details and other NHibernate configurations.
  4. Configure NHibernate in the Startup.cs file of your ASP.NET Core project. This involves setting up the NHibernate factory and registering it as a service.

Installing Evolve

Once NHibernate is set up, we can proceed to install Evolve in our ASP.NET Core project. Here's how:

dotnet add package Evolve

Database Migration Scripts

Evolve uses migration scripts to manage database schema changes. These scripts are written in SQL and are executed in a specific order. Here's an of a migration script:

CREATE TABLE Customers (

Each migration script should be named with a version number and a description. For example, “V1_CreateCustomersTable.sql”.

Applying Database Migrations with Evolve

Once we have our migration scripts , we can use Evolve to apply them to the database. Here's an example of how to use Evolve in an ASP.NET Core :

using Evolve;

public  DatabaseMigration
    public static void Main(string[] args)
        var evolve = new Evolve("evolve.json");

In the above example, we create an instance of the Evolve class and pass the path to the “evolve.json” configuration file. The “Migrate” method is then called to apply the database migrations.


In this article, we have explored how to perform migration using Evolve in ASP.NET Core with NHibernate. We learned about setting up NHibernate, installing Evolve, creating database migration scripts, and applying the migrations using Evolve. By following these steps, you can easily manage and version your database schema changes in your ASP.NET Core application.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents