ASP.NET Identity 2.0上下文添加" 1"到表名。

时间:2014-07-16 20:32:13

标签: asp.net-mvc entity-framework asp.net-identity-2

我不知道为什么会这样。 我有DbContext,它继承自IdentityDbContext:

public class TestContext : IdentityDbContext<ApplicationUser>
    {
        public TestContext()
            : base("name=DomainModelContainer")
        {
        }

        //   protected override void OnModelCreating(DbModelBuilder modelBuilder)
        //  {
        //       throw new UnintentionalCodeFirstException();
        //   }

        public virtual DbSet<AspNetRole> AspNetRoles { get; set; }
        public virtual DbSet<AspNetUserClaim> AspNetUserClaims { get; set; }
        public virtual DbSet<AspNetUserLogin> AspNetUserLogins { get; set; }
        public virtual DbSet<AspNetUser> AspNetUsers { get; set; }

        public virtual DbSet<Blog> Blogs { get; set; }
        public virtual DbSet<Category> Categories { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
            modelBuilder.Entity<AspNetUserLogin>().HasKey<string>(l => l.UserId);
            modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
            modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
            base.OnModelCreating(modelBuilder);
            //modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }
    }

所以当我尝试执行简单的代码时。像

这样的东西
var testContext = new TestContext();
testContext.AspNetRoles.Count();

我收到例外Invalid object name 'dbo.AspNetRoles1'

为什么EF决定在表名中添加“1”?有什么意义?

0 个答案:

没有答案