38 lines
965 B
C#
38 lines
965 B
C#
using AutobusApi.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace AutobusApi.Infrastructure.Data.Configurations;
|
|
|
|
public class UserConfiguration : EntityBaseConfiguration<User>
|
|
{
|
|
public override void Configure(EntityTypeBuilder<User> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder
|
|
.ToTable("users")
|
|
.HasKey(u => u.Id);
|
|
|
|
builder
|
|
.Property(u => u.IdentityId)
|
|
.HasColumnName("identity_id")
|
|
.HasColumnType("int")
|
|
.IsRequired();
|
|
|
|
builder
|
|
.HasIndex(u => u.IdentityId)
|
|
.IsUnique();
|
|
|
|
builder
|
|
.HasMany(u => u.Reviews)
|
|
.WithOne(r => r.User)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
builder
|
|
.HasMany(u => u.TicketGroups)
|
|
.WithOne(tg => tg.User)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|