我不知道为什么会这样。 我有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”?有什么意义?