代码优先使用IdentityUser进行迁移会出错

时间:2014-05-30 09:28:19

标签: asp.net-mvc entity-framework-6 ef-migrations

我尝试使用IdentityUser进行Code First迁移。 这是我的dbContext

public class JbDb : IdentityDbContext<User>
    {
        public JbDb()
            : base(ConfigurationManager.ConnectionStrings["JbDb"].ConnectionString)
        {
        }

        public IDbSet<User> User { get; set; }

        public virtual IDbSet<T> DbSet<T>() where T : class
        {
            return Set<T>();
        }

        public virtual void Commit()
        {
            base.SaveChanges();
        }
    }

    internal class Initialiser : CreateDatabaseIfNotExists<JbDb>
    {
        protected override void Seed(JbDb context)
        {
            context.SaveChanges();
        }
    }

这是“用户模型”的代码

[Table("User", Schema = "Security")]
public class User:IdentityUser
{
    public string UserId
    {
        get { return Id; } 
    }
    public string Email { get; set; }
    public bool IsEmailVerified { get; set; }
    public bool IsDeleted { get; set; }

}

连接字符串是这样的:

 <add name="JbDb" connectionString="Data Source=CENLP\HRMSQL;Initial Catalog=JbDb;Integrated Security=True" providerName="System.Data.SqlClient" />

但是当我尝试启用迁移时,会出错

  
    

检查上下文是否以现有数据库为目标... System.InvalidOperationException:每种类型有多个对象集     不支持。对象设置&#39;用户&#39;和&#39;用户&#39;都可以包含     类型&#39; Jb.Model.Security.User&#39;的实例。在     System.Data.Entity.Internal.DbSetDiscoveryService.RegisterSets(DbModelBuilder     modelBuilder)     System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
    在     System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext     internalContext)at     System.Data.Entity.Internal.RetryLazy 2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps() at System.Data.Entity.Database.Exists() at Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext
1.IsIdentityV1Schema(的DbContext     db)at     Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext 1..ctor(String nameOrConnectionString, Boolean throwIfV1Schema) at Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext 1..ctor(字符串     nameOrConnectionString)在Jb.DataAccess.JbDb..ctor()中     d:\ CENT-Jb \ Jb \ Jb.DataAccess \ JbDb.cs:第10行     ---从抛出异常的先前位置开始的堆栈跟踪结束--- at     System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at     System.Data.Entity.Infrastructure.DbContextInfo.CreateInstance()at     System.Data.Entity.Infrastructure.DbContextInfo..ctor(类型     contextType,DbProviderInfo modelProviderInfo,AppConfig config,     DbConnectionInfo connectionInfo,Func`1 resolver)at     System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration     配置,DbContext usersContext,DatabaseExistenceState     presenceState)at     System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration     配置)     System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration     migrationsConfiguration)at     System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()     在System.AppDomain.DoCallBack(CrossAppDomainDelegate     callBackDelegate)at     System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
    在System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner)     跑者)     System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(字符串     language,String rootNamespace)at     System.Data.Entity.Migrations.EnableMigrationsCommand&LT;&GT; c__DisplayClass2&LT; .ctor&GT; b__0()     在     System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(动作     命令)不支持每种类型的多个对象集。物体     设置&#39;用户&#39;和&#39;用户&#39;都可以包含类型的实例     &#39; Jb.Model.Security.User&#39; ..

  

如果有人可以指出我的错误,那将会非常有用

1 个答案:

答案 0 :(得分:0)

[表格(“用户”,架构=“安全”)]