| | | 1 | | using ArturRios.Heimdall.Domain.Entities; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Data.EntityMaps; |
| | | 6 | | |
| | | 7 | | internal static class ScopeOwnerDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<ScopeOwner> scopeOwner) |
| | | 10 | | { |
| | 3 | 11 | | scopeOwner.ToTable("scope_owner"); |
| | | 12 | | |
| | | 13 | | // Composite key (ScopeId, PersonId); no surrogate Id and no PublicId (§4.5). |
| | 3 | 14 | | scopeOwner.HasKey(x => new { x.ScopeId, x.PersonId }); |
| | | 15 | | |
| | | 16 | | // A scope's owners are removed when the scope is hard-deleted (NFR-08). |
| | 3 | 17 | | scopeOwner.HasOne(x => x.Scope) |
| | 3 | 18 | | .WithMany(s => s.Owners) |
| | 3 | 19 | | .HasForeignKey(x => x.ScopeId) |
| | 3 | 20 | | .OnDelete(DeleteBehavior.Cascade); |
| | | 21 | | |
| | | 22 | | // A ScopeAdmin's ownership rows are removed when the person is hard-deleted (UC-10). |
| | 3 | 23 | | scopeOwner.HasOne(x => x.Person) |
| | 3 | 24 | | .WithMany(p => p.ScopeOwnerships) |
| | 3 | 25 | | .HasForeignKey(x => x.PersonId) |
| | 3 | 26 | | .OnDelete(DeleteBehavior.Cascade); |
| | 3 | 27 | | } |
| | | 28 | | } |