名称不能为null或为空

时间:2016-08-23 05:10:16

标签: asp.net entity-framework-6 asp.net-identity

我首先尝试使用DB的身份,然后我按照此链接https://www.youtube.com/watch?v=elfqejow5hM。我收到错误“名称不能为空或空。”我没有任何列名。并且也没有称为“OnModelCreating”。

这是我的应用程序用户类

public class MyUser : IdentityUser<long, MyLogin, MyUserRole, MyClaim>
{
    public string UserName { get; set; }
}

public class MyUserRole : IdentityUserRole<long> { }

public class MyRole : IdentityRole<long, MyUserRole> { }

public class MyClaim : IdentityUserClaim<long> { }

public class MyLogin : IdentityUserLogin<long> { }

这是我的onmodelcreating代码

        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<MyUser>().ToTable("AspNetUser");
        modelBuilder.Entity<MyUserRole>().ToTable("AspNetRole");
        modelBuilder.Entity<MyRole>().ToTable("AspNetRole");
        modelBuilder.Entity<MyClaim>().ToTable("AspNetUserClaim");
        modelBuilder.Entity<MyLogin>().ToTable("AspNetUserLogin");

        modelBuilder.Entity<MyUser>().Property(r => r.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        modelBuilder.Entity<MyRole>().Property(r => r.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
        modelBuilder.Entity<MyClaim>().Property(r => r.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

我的注册帖法是

          var manager = HttpContext.GetOwinContext().GetUserManager<MyUser>();
            var user = new MyUser()
            {
                Email = model.Email,
                EmailConfirmed = false,
                PhoneNumberConfirmed = false,
                TwoFactorEnabled = false,
                LockoutEndDateUtc = DateTime.Now,
                LockoutEnabled = false,
                AccessFailedCount = 0,
                UserName = model.userName
            };
            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

任何人都可以帮助我解决错误的原因。

0 个答案:

没有答案