48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using AutobusApi.Domain.Entities;
|
|
using AutobusApi.Domain.Enums;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace AutobusApi.Infrastructure.Data.Configurations;
|
|
|
|
public class TicketDocumentConfiguration : EntityBaseConfiguration<TicketDocument>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<TicketDocument> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.ToTable("ticket_documents")
|
|
.HasKey(e => e.Id);
|
|
|
|
builder
|
|
.Property(td => td.Type)
|
|
.HasColumnName("type")
|
|
.HasColumnType("varchar(32)")
|
|
.HasConversion(
|
|
e => e.ToString(),
|
|
s => (TicketDocumentType)Enum.Parse(typeof(TicketDocumentType), s)
|
|
)
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(td => td.Information)
|
|
.HasColumnName("information")
|
|
.HasColumnType("varchar(256)")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.Property(td => td.TicketGroupId)
|
|
.HasColumnName("ticket_group_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasOne(td => td.TicketGroup)
|
|
.WithOne(tg => tg.TicketDocument)
|
|
.HasForeignKey<TicketGroup>(td => td.TicketDocumentId)
|
|
.HasConstraintName("fk_ticketDocuments_ticketGroups_ticketDocumentId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|