11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4+ using System . Security . Cryptography . X509Certificates ;
45using System . Text ;
56using System . Threading . Tasks ;
67using EntityFrameworkCore . Triggered ;
78using Microsoft . EntityFrameworkCore ;
89
910namespace StudentManager
1011{
11- public class Student
12- {
13- public int Id { get ; set ; }
14-
15- public string DisplayName { get ; set ; }
16-
17- public DateTimeOffset RegistrationDate { get ; set ; }
18-
19- public ICollection < StudentCourse > Courses { get ; set ; }
20- }
21-
22- public class Course
23- {
24- public int Id { get ; set ; }
25-
26- public string DisplayName { get ; set ; }
27-
28- public bool IsMandatory { get ; set ; }
29-
30- }
31-
32- public class StudentCourse
33- {
34- public int StudentId { get ; set ; }
35-
36- public int CourseId { get ; set ; }
37-
38- public Student Student { get ; set ; }
39-
40- public Course Course { get ; set ; }
41- }
42-
4312
4413 public class ApplicationContext : TriggeredDbContext
4514 {
@@ -53,6 +22,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
5322 modelBuilder . Entity < StudentCourse > ( )
5423 . HasKey ( x => new { x . StudentId , x . CourseId } ) ;
5524
25+ modelBuilder . Entity < Audit > ( )
26+ . HasKey ( x => new { x . Discriminator , x . Id , x . RecordDate } ) ;
27+
28+ modelBuilder . Entity < Course > ( )
29+ . HasQueryFilter ( x => x . DeletedOn == null ) ;
30+
31+ modelBuilder . Entity < StudentCourse > ( )
32+ . HasQueryFilter ( x => x . Course . DeletedOn == null ) ;
33+
5634 base . OnModelCreating ( modelBuilder ) ;
5735 }
5836
@@ -61,5 +39,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6139 public DbSet < Course > Courses { get ; set ; }
6240
6341 public DbSet < StudentCourse > StudentCourses { get ; set ; }
42+
43+ public DbSet < Audit > Audits { get ; set ; }
6444 }
6545}
0 commit comments