无法在数据库中查找ASP.NET标识表

时间:2016-05-09 07:29:13

标签: asp.net entity-framework ef-code-first asp.net-identity

我使用EF Code-first Migrations方法创建了一个数据库。当我运行应用程序时,我注册了一个用户并期望将身份表添加到我创建的数据库中,但是我找不到这些表。我检查了我的连接字符串,以确保它设置正确。请问我错过了什么?请帮忙。

修改 这是上下文的代码。

public class AppDataContext : DbContext
{
    public AppDataContext()
        : base("AppConnection")
    { }

    public DbSet<AppUser> AppUsers { get; set; }

    public DbSet<Attendance> Attendances { get; set; }

    public DbSet<ClassInfo> Classes { get; set; }

    public DbSet<Enrollment> Enrollments { get; set; }

    public DbSet<MessageBoard> MessageBoards { get; set; }

    public DbSet<Notification> Notifications { get; set; }

    public DbSet<Notification_User> UserNotifications { get; set; }

    public DbSet<NotificationType> NotificationTypes { get; set; }

    public DbSet<Parent> Parents { get; set; }

    public DbSet<ParentSubscription> ParentSubscriptions { get; set; }

    public DbSet<PrivateMessage> PrivateMessages { get; set; }

    public DbSet<School> Schools { get; set; }

    public DbSet<SessionPeriod> SessionPeriods { get; set; }

    public DbSet<Setting> Settings { get; set; }

    public DbSet<Student> Students { get; set; }

    public DbSet<Subject> Subjects { get; set; }

    public DbSet<Teacher> Teachers { get; set; }

    public DbSet<TeacherSchool> TeacherSchools { get; set; }

    public DbSet<Term> Terms { get; set; }

    public DbSet<Work> Works { get; set; }

    public DbSet<WorkType> WorkTypes { get; set; }

    #region Override Methods

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

        modelBuilder.Entity<Subject>()
        .HasMany(c => c.Teachers).WithMany(i => i.Subjects)
        .Map(t => t.MapLeftKey("SubjectID")
        .MapRightKey("TeacherID")
        .ToTable("SubjectTeacher"));

        modelBuilder.Entity<ClassInfo>()
            .HasMany(s => s.Subjects).WithMany(c => c.Classes)
            .Map(u => u.MapLeftKey("ClassInfoID").MapRightKey("SubjectID").ToTable("ClassSubject"));

        //modelBuilder.Entity<Department>().MapToStoredProcedures();

        modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

        //modelBuilder.Entity<ClassInfo>()
        //    .Property(f => f.DateAdded)
        //    .HasColumnType("datetime2");
    }

    #endregion
}

1 个答案:

答案 0 :(得分:0)

注册用户时:

  1. 刷新项目
  2. 显示所有文件
  3. 你会发现:

    enter image description here

    enter image description here

    修改

    IdentityModels.cs:

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            //: base("DefaultConnection", throwIfV1Schema: false)
            : base("AppConnection", throwIfV1Schema: false)
        {
        }
    
        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }
    
    public class AppDataContext : DbContext
    {
        public AppDataContext()
            : base("AppConnection")
        { }
    
    
    }
    

    的Web.config:

     <connectionStrings>
          <add name="AppConnection" connectionString="Data Source=.; Initial Catalog=SIS_DB;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
      </connectionStrings>