我使用DbContext构建了我的项目。我使用代码优先迁移创建并填充了数据库表。最近我意识到我需要在我的项目中实现Identity框架。 DbContext当然没有在DB中创建身份表,所以我想知道什么是最好的方式来替换"通过IdentityDbContext的DbContext,我可以运行“添加 - 迁移”#39;并更新数据库。这是我在我的项目中使用的DbContext类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using Milos_MovieStore.Models;
using Microsoft.AspNet.Identity.EntityFramework;
namespace Milos_MovieStore.DAL
{
public class DBContext_MovieStore : DbContext
{
public DbSet<Customer> Customers { get; set; }
public DbSet<MembershipType> MembershipTypes { get; set; }
public DbSet<Movie> Movies { get; set; }
public DbSet<Genre> Genres { get; set; }
}
}
...当我将基类更改为:
public class DBContext_MovieStore : IdentityDbContext<ApplicationUser>
{
public DbSet<Customer> Customers { get; set; }
public DbSet<MembershipType> MembershipTypes { get; set; }
public DbSet<Movie> Movies { get; set; }
public DbSet<Genre> Genres { get; set; }
}
...它根本没有用(EF异常等),更不用说VS2017每次尝试添加新的迁移时都会崩溃。问题是将Identity实现到项目中的正确方法是什么。