I'm using dotConnect for SQLite 5.1.36 with Entity Framework 6.0.1 Code-First
I'm trying to create automatic migrations with configuration
Code: Select all
internal sealed class SysTypesDbContextMigrationConfiguration : DbMigrationsConfiguration<MyContext>
{
public SysTypesDbContextMigrationConfiguration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = false;
SetSqlGenerator(SQLiteConnectionInfo.InvariantName, new SQLiteEntityMigrationSqlGenerator());
}
}Code: Select all
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, SysTypesDbContextMigrationConfiguration>()); 1)run my sample code - database is created
2)change entities (remove comment in my sample code to add field)
3)enable migrations (remove comment in my sample code near Database.SetInitializer)
then exception is raised
So what should I do?The target context 'EF6Test.MyContext' is not constructible. Add a default constructor or provide an implementation of IDbContextFactory.
Second problem(bug?) is that if I have only configuration in my code (without Database.SetInitializer) and have no database - exception is thrown
That is situation appears without Database.SetInitializer, with CreateDatabaseIfNotExist, DropCreateDatabaseAlways and DropCreateIfModelChanged.Migrations is enabled for context 'MyContext' but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the 'Update-Database' command from the Package Manager Console.
I supposed migrations mechanism to be switched on with
Code: Select all
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, SysTypesDbContextMigrationConfiguration>()); Why SysTypesDbContextMigrationConfiguration is taken into consideration without MigrateDatabaseToLatestVersion?
BTW
Maybe you can reproduce this simply by running my code (without existing database), but I encountered it first time after disabling
Code: Select all
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, SysTypesDbContextMigrationConfiguration>()); UPDATE: One important thing - due to my program limitation I can't use provider registration via config file, all actions have to be done in code.
Here is my sample code:
http://yadi.sk/d/U69J3nEjCfCAa
INFO:
SQLite Code First
Entity Framework 6.0.1
VS 2010 SP1 (.NET 4.0)
dotConnect for SQLite 5.1.36
Windows 7 SP1 32bit