43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Forum.DataAccessLayer.Models;
|
|
using Microsoft.AspNet.Identity.EntityFramework;
|
|
|
|
namespace Forum.DataAccessLayer
|
|
{
|
|
public class ApplicationDbContext : IdentityDbContext<ProfessionalUser>
|
|
{
|
|
public ApplicationDbContext()
|
|
: base("DefaultConnection", throwIfV1Schema: false)
|
|
{
|
|
}
|
|
|
|
public static ApplicationDbContext Create()
|
|
{
|
|
return new ApplicationDbContext();
|
|
}
|
|
|
|
public DbSet<Answer> Answers { get; set; }
|
|
|
|
public DbSet<Question> Questions { get; set; }
|
|
|
|
public DbSet<Category> Categories { get; set; }
|
|
|
|
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<Question>().HasMany(a => a.Answers).WithOptional(q => q.Question);
|
|
|
|
modelBuilder.Entity<Answer>().HasOptional(p => p.Professional);
|
|
|
|
modelBuilder.Entity<Category>().HasMany(q => q.Questions).WithRequired(c => c.Category);
|
|
|
|
}
|
|
}
|
|
}
|