| | | 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 ScopeUserDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<ScopeUser> scopeUser) |
| | | 10 | | { |
| | 3 | 11 | | scopeUser.ToTable("scope_user"); |
| | | 12 | | |
| | | 13 | | // Composite key (ScopeId, PersonId); no surrogate Id and no PublicId (§4.6). |
| | 3 | 14 | | scopeUser.HasKey(x => new { x.ScopeId, x.PersonId }); |
| | | 15 | | |
| | | 16 | | // A scope's users are removed when the scope is hard-deleted (NFR-08). |
| | 3 | 17 | | scopeUser.HasOne(x => x.Scope) |
| | 3 | 18 | | .WithMany(s => s.Users) |
| | 3 | 19 | | .HasForeignKey(x => x.ScopeId) |
| | 3 | 20 | | .OnDelete(DeleteBehavior.Cascade); |
| | | 21 | | |
| | | 22 | | // One-to-one with Person: a User belongs to exactly one scope, so PersonId is unique across |
| | | 23 | | // this table (§4.6). The single-navigation reciprocal is Person.ScopeMembership. The |
| | | 24 | | // membership row is removed when the person is hard-deleted (UC-10). |
| | 3 | 25 | | scopeUser.HasOne(x => x.Person) |
| | 3 | 26 | | .WithOne(p => p.ScopeMembership) |
| | 3 | 27 | | .HasForeignKey<ScopeUser>(x => x.PersonId) |
| | 3 | 28 | | .OnDelete(DeleteBehavior.Cascade); |
| | 3 | 29 | | } |
| | | 30 | | } |