-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplicationDbContext.cs
45 lines (38 loc) · 1.55 KB
/
ApplicationDbContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using eTickets.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace eTickets.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<Actor> Actors { get; set; }
public DbSet<Movie> Movies { get; set; }
public DbSet<ActorMovie> ActorMovies { get; set; }
public DbSet<Cinema> Cinemas { get; set; }
public DbSet<Producer> Producers { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
public DbSet<ShoppingCartItem> ShoppingCartItems { get; set; }
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ActorMovie>().HasKey(x => new
{
x.MovieId,
x.ActorId
});
modelBuilder.Entity<ActorMovie>().HasOne(x => x.Movie).WithMany(x => x.ActorsMovies).HasForeignKey(x => x.MovieId);
modelBuilder.Entity<ActorMovie>().HasOne(x => x.Actor).WithMany(x => x.ActorsMovies).HasForeignKey(x=>x.ActorId);
}
}
}