| | | 1 | | using AsiBackbone.EntityFrameworkCore.Persistence; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | |
| | | 5 | | namespace AsiBackbone.EntityFrameworkCore.Configurations; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Configures the Entity Framework Core persistence mapping for <see cref="AsiBackboneAuditResidueLifecycleEventEntity" |
| | | 9 | | /// </summary> |
| | | 10 | | public sealed class AsiBackboneAuditResidueLifecycleEventEntityConfiguration |
| | | 11 | | : IEntityTypeConfiguration<AsiBackboneAuditResidueLifecycleEventEntity> |
| | | 12 | | { |
| | | 13 | | private const int IdentifierMaxLength = 128; |
| | | 14 | | private const int StageMaxLength = 128; |
| | | 15 | | private const int OperationNameMaxLength = 256; |
| | | 16 | | private const int OutcomeMaxLength = 128; |
| | | 17 | | private const int ConcurrencyStampMaxLength = 64; |
| | | 18 | | |
| | | 19 | | /// <inheritdoc /> |
| | | 20 | | public void Configure(EntityTypeBuilder<AsiBackboneAuditResidueLifecycleEventEntity> builder) |
| | | 21 | | { |
| | 22 | 22 | | ArgumentNullException.ThrowIfNull(builder); |
| | | 23 | | |
| | 22 | 24 | | _ = builder.ToTable("AsiBackboneAuditResidueLifecycleEvents"); |
| | | 25 | | |
| | 22 | 26 | | _ = builder.HasKey(lifecycleEvent => lifecycleEvent.Id); |
| | | 27 | | |
| | 22 | 28 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.Id) |
| | 22 | 29 | | .ValueGeneratedNever(); |
| | | 30 | | |
| | 22 | 31 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.ConcurrencyStamp) |
| | 22 | 32 | | .IsRequired() |
| | 22 | 33 | | .HasMaxLength(ConcurrencyStampMaxLength) |
| | 22 | 34 | | .IsConcurrencyToken(); |
| | | 35 | | |
| | 22 | 36 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.EventId) |
| | 22 | 37 | | .IsRequired() |
| | 22 | 38 | | .HasMaxLength(IdentifierMaxLength); |
| | | 39 | | |
| | 22 | 40 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.Stage) |
| | 22 | 41 | | .HasConversion<string>() |
| | 22 | 42 | | .IsRequired() |
| | 22 | 43 | | .HasMaxLength(StageMaxLength); |
| | | 44 | | |
| | 22 | 45 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.StageSequence) |
| | 22 | 46 | | .IsRequired(); |
| | | 47 | | |
| | 22 | 48 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.OccurredUtc) |
| | 22 | 49 | | .IsRequired(); |
| | | 50 | | |
| | 22 | 51 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.CorrelationId) |
| | 22 | 52 | | .IsRequired() |
| | 22 | 53 | | .HasMaxLength(IdentifierMaxLength); |
| | | 54 | | |
| | 22 | 55 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.AuditResidueId) |
| | 22 | 56 | | .HasMaxLength(IdentifierMaxLength); |
| | | 57 | | |
| | 22 | 58 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.TraceId) |
| | 22 | 59 | | .HasMaxLength(IdentifierMaxLength); |
| | | 60 | | |
| | 22 | 61 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.OperationName) |
| | 22 | 62 | | .HasMaxLength(OperationNameMaxLength); |
| | | 63 | | |
| | 22 | 64 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.Outcome) |
| | 22 | 65 | | .HasMaxLength(OutcomeMaxLength); |
| | | 66 | | |
| | 22 | 67 | | _ = builder.Property(lifecycleEvent => lifecycleEvent.MetadataJson) |
| | 22 | 68 | | .IsRequired(); |
| | | 69 | | |
| | 22 | 70 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.EventId) |
| | 22 | 71 | | .IsUnique(); |
| | | 72 | | |
| | 22 | 73 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.Stage); |
| | | 74 | | |
| | 22 | 75 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.StageSequence); |
| | | 76 | | |
| | 22 | 77 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.OccurredUtc); |
| | | 78 | | |
| | 22 | 79 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.CorrelationId); |
| | | 80 | | |
| | 22 | 81 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.AuditResidueId); |
| | | 82 | | |
| | 22 | 83 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.TraceId); |
| | | 84 | | |
| | 22 | 85 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.OperationName); |
| | | 86 | | |
| | 22 | 87 | | _ = builder.HasIndex(lifecycleEvent => lifecycleEvent.Outcome); |
| | | 88 | | |
| | 22 | 89 | | _ = builder.HasIndex(lifecycleEvent => new |
| | 22 | 90 | | { |
| | 22 | 91 | | lifecycleEvent.CorrelationId, |
| | 22 | 92 | | lifecycleEvent.OccurredUtc |
| | 22 | 93 | | }); |
| | | 94 | | |
| | 22 | 95 | | _ = builder.HasIndex(lifecycleEvent => new |
| | 22 | 96 | | { |
| | 22 | 97 | | lifecycleEvent.AuditResidueId, |
| | 22 | 98 | | lifecycleEvent.OccurredUtc |
| | 22 | 99 | | }); |
| | 22 | 100 | | } |
| | | 101 | | } |