using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; using Microsoft.AspNet.Identity.EntityFramework; using RSystem.Models; namespace RSystem.DAL { public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { this.Configuration.LazyLoadingEnabled = false; //Database.SetInitializer(new CreateDatabaseIfNotExists()); } public DbSet Recruits { get; set; } public DbSet RecruitDatas { get; set; } public DbSet RecruitPreferences { get; set; } public DbSet Specializations { get; set; } public DbSet Faculties { get; set; } public DbSet MaturaSubjects { get; set; } public DbSet MaturaResults { get; set; } public DbSet PointsMultipilers { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity() .HasRequired(r => r.RecriutData) .WithRequiredPrincipal(r => r.Recruit); modelBuilder.Entity() .HasRequired(u => u.ApplicationUser); modelBuilder.Entity() .HasMany(r => r.RecruitPreferences) .WithRequired(s => s.Specialization); modelBuilder.Entity() .HasMany(r => r.AcceptedRecruits) .WithOptional(s => s.AcceptedSpecialization); modelBuilder.Entity() .HasMany(r => r.RecruitPreferences) .WithRequired(r => r.Recruit); modelBuilder.Entity() .HasRequired(s => s.Faculty) .WithMany(s => s.Specializations); modelBuilder.Entity() .HasMany(m => m.MaturaResults) .WithRequired(r => r.Recruit); modelBuilder.Entity() .HasRequired(m => m.MaturaSubject); modelBuilder.Entity() .HasMany(p => p.PointsMultipilers) .WithRequired(s => s.Specialization); modelBuilder.Entity() .HasRequired(m => m.MaturaSubject); } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } } }