I've been trying to follow the advice of Ben Cull (http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-projects), but the database is a little different in that I'm trying to inherit from ASP.NET Core IdentityUser class. I created a new solution containing the default ASP.NET Core Web Application from the VS2015 template (CodeFirstTest). I then added an ASP.NET Core class-library (CodeFirstTest.User) to the solution, which would be the data layer in the application and where I will also be setting up ASP.NET Core Identity.
Following the advice of Ben Cull, I rewrote the CodeFirstTest.User project.json as follows.
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.Extensions.Configuration": "1.0.1",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.Design": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}
}
I also created a Program.cs file containing the entry point, and a User class that inherits from ASP.NET Core IdentityUser as shown below.
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace CodeFirstTest.User
{
public class Program
{
public static void Main(string[] args) { }
}
public class User : IdentityUser
{
}
public class UserIdentityDbContext : IdentityDbContext<User>
{
public UserIdentityDbContext(DbContextOptions options)
{
}
}
public class TemporaryDbContextFactory : IDbContextFactory<UserIdentityDbContext>
{
public UserIdentityDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<UserIdentityDbContext>();
builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=UserDb;Trusted_Connection=SqlTruncateException;MultipleActiveResultSets=true");
return new UserIdentityDbContext(builder.Options);
}
}
}
When I use the Project Manager Console to create the initial migration, I received the following errors.
PM> Add-Migration -Name "Initial" -Project "CodeFirstTest.User"
Could not invoke this command with the startup project 'CodeFirstTest'. Check that 'Microsoft.EntityFrameworkCore.Design' has been added to "dependencies" in the startup project and that the version of 'Microsoft.EntityFrameworkCore.Tools' in "tools" and 'Microsoft.EntityFrameworkCore.Design' are the same. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.
PM> Add-Migration -Name "Initial" -Project "CodeFirstTest.User"
Unhandled Exception: System.MissingMethodException: Entry point not found in assembly 'Microsoft.EntityFrameworkCore.Design, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I corrected the first error, but the second run will cause dotnet to fail with the 'Unhandled Exception' error. The question... Am I coding something incorrectly that prevents the migration from executing?
Thank you.
