2024-08-17 16:38:40 +02:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
|
|
using Vegasco.WebApi.Users;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Vegasco.WebApi.Cars;
|
2024-08-17 16:38:40 +02:00
|
|
|
|
|
|
|
|
|
|
public class Car
|
|
|
|
|
|
{
|
|
|
|
|
|
public Guid Id { get; set; } = Guid.NewGuid();
|
|
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; } = "";
|
|
|
|
|
|
|
2024-08-17 16:38:40 +02:00
|
|
|
|
public string UserId { get; set; } = "";
|
|
|
|
|
|
|
|
|
|
|
|
public virtual User User { get; set; } = null!;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class CarTableConfiguration : IEntityTypeConfiguration<Car>
|
|
|
|
|
|
{
|
|
|
|
|
|
public const int NameMaxLength = 50;
|
|
|
|
|
|
|
|
|
|
|
|
public void Configure(EntityTypeBuilder<Car> builder)
|
|
|
|
|
|
{
|
|
|
|
|
|
builder.HasKey(x => x.Id);
|
|
|
|
|
|
|
|
|
|
|
|
builder.Property(x => x.Name)
|
|
|
|
|
|
.IsRequired()
|
|
|
|
|
|
.HasMaxLength(NameMaxLength);
|
|
|
|
|
|
|
|
|
|
|
|
builder.Property(x => x.UserId)
|
|
|
|
|
|
.IsRequired();
|
|
|
|
|
|
|
|
|
|
|
|
builder.HasOne(x => x.User)
|
|
|
|
|
|
.WithMany(x => x.Cars);
|
|
|
|
|
|
}
|
2024-08-17 16:38:40 +02:00
|
|
|
|
}
|