|
| 1 | +using System; |
1 | 2 | using JsonApiDotNetCoreExample.Models;
|
| 3 | +using Microsoft.AspNetCore.Authentication; |
2 | 4 | using Microsoft.EntityFrameworkCore;
|
3 | 5 |
|
4 | 6 | namespace JsonApiDotNetCoreExample.Data
|
5 | 7 | {
|
6 | 8 | public sealed class AppDbContext : DbContext
|
7 | 9 | {
|
| 10 | + public ISystemClock SystemClock { get; } |
| 11 | + |
8 | 12 | public DbSet<TodoItem> TodoItems { get; set; }
|
9 | 13 | public DbSet<Passport> Passports { get; set; }
|
10 | 14 | public DbSet<Person> People { get; set; }
|
11 | 15 | public DbSet<TodoItemCollection> TodoItemCollections { get; set; }
|
12 | 16 | public DbSet<KebabCasedModel> KebabCasedModels { get; set; }
|
13 | 17 | public DbSet<Article> Articles { get; set; }
|
14 | 18 | public DbSet<Author> AuthorDifferentDbContextName { get; set; }
|
15 |
| - public DbSet<NonJsonApiResource> NonJsonApiResources { get; set; } |
16 | 19 | public DbSet<User> Users { get; set; }
|
17 |
| - public DbSet<SuperUser> SuperUsers { get; set; } |
18 | 20 | public DbSet<PersonRole> PersonRoles { get; set; }
|
19 | 21 | public DbSet<ArticleTag> ArticleTags { get; set; }
|
20 |
| - public DbSet<IdentifiableArticleTag> IdentifiableArticleTags { get; set; } |
21 | 22 | public DbSet<Tag> Tags { get; set; }
|
22 |
| - public DbSet<ThrowingResource> ThrowingResources { get; set; } |
23 | 23 |
|
24 |
| - public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { } |
| 24 | + public AppDbContext(DbContextOptions<AppDbContext> options, ISystemClock systemClock) : base(options) |
| 25 | + { |
| 26 | + SystemClock = systemClock ?? throw new ArgumentNullException(nameof(systemClock)); |
| 27 | + } |
25 | 28 |
|
26 | 29 | protected override void OnModelCreating(ModelBuilder modelBuilder)
|
27 | 30 | {
|
| 31 | + modelBuilder.Entity<ThrowingResource>(); |
| 32 | + |
28 | 33 | modelBuilder.Entity<SuperUser>().HasBaseType<User>();
|
29 | 34 |
|
30 | 35 | modelBuilder.Entity<TodoItem>()
|
@@ -66,6 +71,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
|
66 | 71 | .HasForeignKey<Person>(p => p.PassportId)
|
67 | 72 | .OnDelete(DeleteBehavior.SetNull);
|
68 | 73 |
|
| 74 | + modelBuilder.Entity<Passport>() |
| 75 | + .HasMany(passport => passport.GrantedVisas) |
| 76 | + .WithOne() |
| 77 | + .OnDelete(DeleteBehavior.Cascade); |
| 78 | + |
69 | 79 | modelBuilder.Entity<TodoItem>()
|
70 | 80 | .HasOne(p => p.OneToOnePerson)
|
71 | 81 | .WithOne(p => p.OneToOneTodoItem)
|
|
0 commit comments