40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using Microsoft.AspNet.Identity.EntityFramework;
|
|
using MovieBase.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace MovieBase.DAL
|
|
{
|
|
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
|
{
|
|
public DbSet<Movie> Movies { get; set; }
|
|
//public DbSet<Actor> Actors { get; set; }
|
|
|
|
public ApplicationDbContext()
|
|
: base("DefaultConnection", throwIfV1Schema: false)
|
|
{
|
|
}
|
|
|
|
public static ApplicationDbContext Create()
|
|
{
|
|
return new ApplicationDbContext();
|
|
}
|
|
|
|
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Movie>().Property(x => x.MovieId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
|
|
//modelBuilder.Entity<Actor>().Property(x => x.ActorId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
|
|
|
|
modelBuilder.Entity<Movie>().HasKey(movie => movie.MovieId);
|
|
//modelBuilder.Entity<Actor>().HasKey(actor => actor.ActorId);
|
|
|
|
//modelBuilder.Entity<Movie>().HasMany(movie => movie.StarringActors).WithMany(actor => actor.Movies);
|
|
modelBuilder.Entity<ApplicationUser>().HasMany(user => user.WatchedMovies).WithMany(movie => movie.WatchedByUsers);
|
|
base.OnModelCreating(modelBuilder);
|
|
}
|
|
}
|
|
} |