| | | 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="AsiBackboneAuditLedgerReasonCodeEntity" />. |
| | | 9 | | /// </summary> |
| | | 10 | | public sealed class AsiBackboneAuditLedgerReasonCodeEntityConfiguration |
| | | 11 | | : IEntityTypeConfiguration<AsiBackboneAuditLedgerReasonCodeEntity> |
| | | 12 | | { |
| | | 13 | | private const int ReasonCodeMaxLength = 256; |
| | | 14 | | private const int ConcurrencyStampMaxLength = 64; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public void Configure(EntityTypeBuilder<AsiBackboneAuditLedgerReasonCodeEntity> builder) |
| | | 18 | | { |
| | 22 | 19 | | ArgumentNullException.ThrowIfNull(builder); |
| | | 20 | | |
| | 22 | 21 | | _ = builder.ToTable("AsiBackboneAuditLedgerReasonCodes"); |
| | | 22 | | |
| | 22 | 23 | | _ = builder.HasKey(reasonCode => reasonCode.Id); |
| | | 24 | | |
| | 22 | 25 | | _ = builder.Property(reasonCode => reasonCode.Id) |
| | 22 | 26 | | .ValueGeneratedNever(); |
| | | 27 | | |
| | 22 | 28 | | _ = builder.Property(reasonCode => reasonCode.ConcurrencyStamp) |
| | 22 | 29 | | .IsRequired() |
| | 22 | 30 | | .HasMaxLength(ConcurrencyStampMaxLength) |
| | 22 | 31 | | .IsConcurrencyToken(); |
| | | 32 | | |
| | 22 | 33 | | _ = builder.Property(reasonCode => reasonCode.AuditLedgerRecordId) |
| | 22 | 34 | | .IsRequired(); |
| | | 35 | | |
| | 22 | 36 | | _ = builder.Property(reasonCode => reasonCode.Sequence) |
| | 22 | 37 | | .IsRequired(); |
| | | 38 | | |
| | 22 | 39 | | _ = builder.Property(reasonCode => reasonCode.ReasonCode) |
| | 22 | 40 | | .IsRequired() |
| | 22 | 41 | | .HasMaxLength(ReasonCodeMaxLength); |
| | | 42 | | |
| | 22 | 43 | | _ = builder.HasOne(reasonCode => reasonCode.AuditLedgerRecord) |
| | 22 | 44 | | .WithMany() |
| | 22 | 45 | | .HasForeignKey(reasonCode => reasonCode.AuditLedgerRecordId) |
| | 22 | 46 | | .OnDelete(DeleteBehavior.Cascade); |
| | | 47 | | |
| | 22 | 48 | | _ = builder.HasIndex(reasonCode => reasonCode.AuditLedgerRecordId); |
| | | 49 | | |
| | 22 | 50 | | _ = builder.HasIndex(reasonCode => reasonCode.ReasonCode); |
| | | 51 | | |
| | 22 | 52 | | _ = builder.HasIndex(reasonCode => new |
| | 22 | 53 | | { |
| | 22 | 54 | | reasonCode.AuditLedgerRecordId, |
| | 22 | 55 | | reasonCode.Sequence |
| | 22 | 56 | | }) |
| | 22 | 57 | | .IsUnique(); |
| | | 58 | | |
| | 22 | 59 | | _ = builder.HasIndex(reasonCode => new |
| | 22 | 60 | | { |
| | 22 | 61 | | reasonCode.AuditLedgerRecordId, |
| | 22 | 62 | | reasonCode.ReasonCode |
| | 22 | 63 | | }); |
| | 22 | 64 | | } |
| | | 65 | | } |