using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using StudentDAL.EntityConfigurations;
using StudentModels;

namespace StudentMVC.Models
{
    public class StudentDbContext : DbContext
    {
        public StudentDbContext()
            : base("StudentDbConnectionString")
        {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<StudentDbContext>());
           
        }

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

            //comment out all the configurations for scaffolding

            modelBuilder.Configurations.Add(new GradeConfiguration());
            modelBuilder.Configurations.Add(new GradeSystemConfiguration());
            modelBuilder.Configurations.Add(new StudentConfiguration());
            modelBuilder.Configurations.Add(new StudentInSubjectConfiguration());
            modelBuilder.Configurations.Add(new SubjectConfiguration());
            modelBuilder.Configurations.Add(new TeacherConfiguration());
            
            base.OnModelCreating(modelBuilder);
        }

        public DbSet<Student> Students { get; set; }
        public DbSet<StudentInSubject> StudentInSubjects { get; set; }
        public DbSet<Subject> Subjects { get; set; }
        public DbSet<Teacher> Teachers { get; set; }

        public DbSet<GradeSystem> GradeSystems { get; set; }

        public DbSet<Grade> Grades { get; set; }

    }
}
