Entity Framework 6 throws migration exception when trying to create a context with Effort


I'm trying to use Effort to test my application but if code-first migrations are enabled on the context then it throws the following exception:

System.InvalidOperationException: Migrations is enabled for context 'XDbContext' 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.

If I disable migrations then it all works fine.

How do I stop entity from even considering the migrations for the purposes of my tests.

Popular Answer

I kept getting the same error in my unit testing project. I solved it by modifying the TestInitialize function by calling the CreateIfNotExist() function

    public void Initialize()
        DbConnection connection = Effort.DbConnectionFactory.CreateTransient();

        context = new MyAccessContext(connection);
        service = new YourClass(context);

Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why