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 { public DbSet Movies { get; set; } //public DbSet Actors { get; set; } public ApplicationDbContext() : base("DefaultConnection", throwIfV1Schema: false) { } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity().Property(x => x.MovieId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); //modelBuilder.Entity().Property(x => x.ActorId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); modelBuilder.Entity().HasKey(movie => movie.MovieId); //modelBuilder.Entity().HasKey(actor => actor.ActorId); //modelBuilder.Entity().HasMany(movie => movie.StarringActors).WithMany(actor => actor.Movies); modelBuilder.Entity().HasMany(user => user.WatchedMovies).WithMany(movie => movie.WatchedByUsers); base.OnModelCreating(modelBuilder); } } }