我正在尝试将Entity Framework和Identity分离到另一个库,但是使用时我无法进行任何迁移builder.UseInMemoryDatabase(connectionString);。
更改为时,我可以进行迁移builder.UseSqlServer(connectionString);,但是我需要使用UseInMemoryDatabase。
当我尝试添加迁移时,这是错误:
无法解析类型为Microsoft.EntityFrameworkCore.Migrations.IMigrator的服务。这通常是因为尚未为此DbContext配置任何数据库提供程序。可以通过重写DbContext.OnConfiguring方法或在应用程序服务提供程序上使用AddDbContext来配置提供程序。如果使用AddDbContext,则还应确保DbContext类型在其构造函数中接受DbContextOptions对象,并将其传递给DbContext的基本构造函数。
码:
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.InMemory;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
namespace ClassLibrary1
{
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
base.OnModelCreating(modelBuilder);
}
}
public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContextFactory()
{
}
public ApplicationDbContext CreateDbContext(string[] args)
{
IConfigurationRoot configuration = new …Run Code Online (Sandbox Code Playgroud)