44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using AutobusApi.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace AutobusApi.Persistence.Contexts.Configurations;
|
|
|
|
public class TicketConfiguration : EntityBaseConfiguration<Ticket>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<Ticket> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.ToTable("tickets")
|
|
.HasKey(e => e.Id);
|
|
|
|
builder
|
|
.Property(t => t.VehicleEnrollmentId)
|
|
.HasColumnName("vehicle_enrollment_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasOne(t => t.VehicleEnrollment)
|
|
.WithMany(ve => ve.Tickets)
|
|
.HasForeignKey(t => t.VehicleEnrollmentId)
|
|
.HasConstraintName("fk_tickets_vehicleEnrollments_vehicleEnrollmentId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.Property(t => t.TicketGroupId)
|
|
.HasColumnName("ticket_group_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasOne(t => t.TicketGroup)
|
|
.WithMany(ve => ve.Tickets)
|
|
.HasForeignKey(t => t.TicketGroupId)
|
|
.HasConstraintName("fk_tickets_ticketGroups_ticketGroupId")
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|