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