Using Migrations¶
(It is only applicable for the ExtCore framework version 3.1.0-beta1 and higher.)
Migrations feature is only available if you are using Entity Framework Core as the ORM. To make it possible to use the Migrations tool, please, follow these steps:
1. Create the DesignTimeStorageContextFactory
class (you can use any name) and inherit it from the
ExtCore.Data.EntityFramework.DesignTimeStorageContextFactoryBase<T>
one (here T
is the type of the storage context you are using). You don’t need to implement any methods in this class:
public class DesignTimeStorageContextFactory : DesignTimeStorageContextFactoryBase<StorageContext>
{
}
2. Initialize the StorageContextOptions.MigrationsAssembly
property with the name of the assembly (project) where
the DesignTimeStorageContextFactory
class is created:
services.Configure<StorageContextOptions>(options =>
{
options.ConnectionString = this.configurationRoot.GetConnectionString("Default");
options.MigrationsAssembly = typeof(DesignTimeStorageContextFactory).GetTypeInfo().Assembly.FullName;
}
);
- Call the
DesignTimeStorageContextFactory.Initialize()
static method after theStorageContextOptions
class configuration:
DesignTimeStorageContextFactory.Initialize(services.BuildServiceProvider());
That’s all, now you can use the Migrations tool.