Проблема решена, вот решение.
Класс:
- CustomDbContext, CustomMigrationsConfiguration
- ReusableContext, ReusableMigrationsConfiguration < TContext >
- DbContext
Отношение:
- ReusableContext: DbContext
- ReusableMigrationsConfiguration < TContext >: DbMigrationsConfiguration < TContext > где TContext: ReusableContext
- CustomMigrationsConfiguration: ReusableMigrationsConfiguration < CustomDbContext >
Код:
public class ReusableDbContext : DbContext
{
public ReusableDbContext()
: base("name = myConnectionString")
{
Database.SetInitializer<ReusableDbContext>(new
MigrateDatabaseToLatestVersion<ReusableDbContext, ReusableMigrationsConfiguration>());
}
public DbSet<ReusableTable> ReusableTables{ get; set; }
}
public class ReusableMigrationsConfiguration<TContext> : DbMigrationsConfiguration<TContext> where TContext : ReusableDbContext
{
public ReusableMigrationsConfiguration()
: base()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(TContext context)
{
//ReusableMigrationsConfiguration Seed Logic here
// is called and OK now.
}
}
Теперь мы можем повторно использовать ReusableContext следующим образом:
public class CustomDbContext : ReusableDbContext
{
public CustomDbContext()
: base()
{
Database.SetInitializer<CustomDbContext>(new
MigrateDatabaseToLatestVersion<CustomDbContext, CustomMigrationsConfiguration>());
}
public DbSet<CustomTable> CustomTables{ get; set; }
}
public class CustomMigrationsConfiguration : ReusableMigrationsConfiguration<CustomDbContext>
{
public CustomMigrationsConfiguration()
: base()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}
protected override void Seed(CustomDbContext context)
{
base.Seed(context);
//CustomMigrationsConfiguration Seed Logic
// this Seed method is called and OK
}
}
после запуска проекта:
- Создаются ReusableTable и CustomTable;
- Вызывается метод Seed для CustomMigrationsConfiguration и OK;
- Вызывается метод Seed для ReusableMigrationsConfiguration и OKтоже.
сейчас все вроде бы нормально:)