VS2017 will be officially released on the 7th of March 2017. The doc concerns VS2015, they have not been updated yet to reflect the latest VS 2017 changes. Modifying the csproject like this solves the problem:
<ItemGroup> <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.0" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version = "1.1.0-preview4-final"/> </ItemGroup>
Even after this, when I tried to run the first migration with the CLI command:
dotnet ef migrations add MyFirstMigration
I got the following error: “No parameterless constructor was found on 'TContext'. Either add a parameterless constructor to 'TContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'TContext'.”
According to this document, this happens because design-time tools attempt to automatically find how your application creates instances of your DbContext type. If EF cannot find a suitable way to initialize your DbContext, you may encounter this error.
I was pretty sure I had setup a parameterless constructor and I was able to see the context with the following CLI command:
dotnet ef database dbContext list
The only way to perform the migration has been to implement the interface IDbContextFactory<TContext> in the project. The documentation and the examples on how to do this are based on VS 2015. In VS 2017 IDbContextFactory<TContext>.Create() wants a DBContextFactoryOptions as parameter:
public class MyContextFactory: IDbContextFactory<MyContext> { public MyContext Create(DbContextFactoryOptions options) { var optionsBuilder = new DbContextOptionsBuilder<MyContext>(); optionsBuilder.UseSqlite("Filename=./mydatabase.db"); return new MyContext(optionsBuilder.Options); } }