1+ using DataAccessLayer . Models ;
2+ using Microsoft . AspNetCore . Identity . EntityFrameworkCore ;
3+ using Microsoft . EntityFrameworkCore ;
4+ using System ;
5+
6+ namespace DataAccessLayer
7+ {
8+ public class ApplicationDbContext : IdentityDbContext < ApplicationUser , ApplicationRole , long >
9+ {
10+ public ApplicationDbContext ( DbContextOptions options )
11+ : base ( options )
12+ {
13+
14+ }
15+
16+ public DbSet < Idea > Ideas { get ; set ; }
17+ public DbSet < Comment > Comments { get ; set ; }
18+ public DbSet < Tag > Tags { get ; set ; }
19+ public DbSet < relIdeaTag > relIdeaTags { get ; set ; }
20+ public DbSet < relIdeaFavorite > relIdeaFavorites { get ; set ; }
21+ public DbSet < relIdeaLike > relIdeaLikes { get ; set ; }
22+ public DbSet < relCommentLike > relCommentLikes { get ; set ; }
23+
24+ protected override void OnModelCreating ( ModelBuilder builder )
25+ {
26+ base . OnModelCreating ( builder ) ;
27+
28+ builder . Entity < Idea > ( )
29+ . HasOne ( x => x . CreatorUser )
30+ . WithMany ( x => x . Ideas )
31+ . HasForeignKey ( x => x . CreatorId ) ;
32+
33+ builder . Entity < Comment > ( )
34+ . HasOne ( x => x . CreatorUser )
35+ . WithMany ( x => x . Comments )
36+ . HasForeignKey ( x => x . CreatorId ) ;
37+
38+ builder . Entity < Comment > ( )
39+ . HasOne ( x => x . Idea )
40+ . WithMany ( x => x . Comments )
41+ . HasForeignKey ( x => x . IdeaId ) ;
42+
43+ builder . Entity < Tag > ( )
44+ . HasOne ( x => x . CreatorUser )
45+ . WithMany ( x => x . Tags )
46+ . HasForeignKey ( x => x . CreatorId ) ;
47+
48+ builder . Entity < relIdeaFavorite > ( )
49+ . HasOne ( x => x . CreatorUser )
50+ . WithMany ( x => x . relIdeaFavorites )
51+ . HasForeignKey ( x => x . CreatorId ) ;
52+
53+ builder . Entity < relIdeaFavorite > ( )
54+ . HasOne ( x => x . Idea )
55+ . WithMany ( x => x . Favorites )
56+ . HasForeignKey ( x => x . IdeaId ) ;
57+
58+ builder . Entity < relIdeaTag > ( )
59+ . HasOne ( x => x . CreatorUser )
60+ . WithMany ( x => x . relIdeaTags )
61+ . HasForeignKey ( x => x . CreatorId ) ;
62+
63+ builder . Entity < relIdeaTag > ( )
64+ . HasOne ( x => x . Tag )
65+ . WithMany ( x => x . IdeaTags )
66+ . HasForeignKey ( x => x . TagId ) ;
67+
68+ builder . Entity < relIdeaTag > ( )
69+ . HasOne ( x => x . Idea )
70+ . WithMany ( x => x . Tags )
71+ . HasForeignKey ( x => x . IdeaId ) ;
72+
73+ builder . Entity < relIdeaLike > ( )
74+ . HasOne ( x => x . CreatorUser )
75+ . WithMany ( x => x . relIdeaLikes )
76+ . HasForeignKey ( x => x . CreatorId ) ;
77+
78+ builder . Entity < relIdeaLike > ( )
79+ . HasOne ( x => x . Idea )
80+ . WithMany ( x => x . Likes )
81+ . HasForeignKey ( x => x . IdeaId ) ;
82+
83+ builder . Entity < relCommentLike > ( )
84+ . HasOne ( x => x . CreatorUser )
85+ . WithMany ( x => x . relCommentLikes )
86+ . HasForeignKey ( x => x . CreatorId ) ;
87+
88+ builder . Entity < relCommentLike > ( )
89+ . HasOne ( x => x . Comment )
90+ . WithMany ( x => x . Likes )
91+ . HasForeignKey ( x => x . CommentId ) ;
92+
93+ }
94+ }
95+ }
0 commit comments