using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Vegasco.Server.Api.Consumptions; using Vegasco.Server.Api.Users; namespace Vegasco.Server.Api.Cars; public class Car { public CarId Id { get; set; } = CarId.New(); public string Name { get; set; } = ""; public string UserId { get; set; } = ""; public virtual User User { get; set; } = null!; public virtual ICollection Consumptions { get; set; } = []; } public class CarTableConfiguration : IEntityTypeConfiguration { public const int NameMaxLength = 50; public void Configure(EntityTypeBuilder builder) { builder.HasKey(x => x.Id); builder.Property(x => x.Id) .HasConversion(); builder.Property(x => x.Name) .IsRequired() .HasMaxLength(NameMaxLength); builder.Property(x => x.UserId) .IsRequired(); builder.HasOne(x => x.User) .WithMany(x => x.Cars); } }