using System.Data.Entity; using Forum.DataAccessLayer.Models; using Microsoft.AspNet.Identity.EntityFramework; namespace Forum.DataAccessLayer { public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } public DbSet Answers { get; set; } public DbSet Questions { get; set; } public DbSet Categories { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasMany(a => a.Answers).WithOptional(q => q.Question); modelBuilder.Entity().HasOptional(p => p.Professional); modelBuilder.Entity().HasMany(q => q.Questions).WithRequired(c => c.Category); } } }