using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Vegasco.WebApi.Cars; namespace Vegasco.WebApi.Consumptions; public class Consumption { public ConsumptionId Id { get; set; } = ConsumptionId.New(); public DateTimeOffset DateTime { get; set; } public double Distance { get; set; } public double Amount { get; set; } public bool IgnoreInCalculation { get; set; } public CarId CarId { get; set; } public virtual Car Car { get; set; } = null!; } public class ConsumptionTableConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasKey(x => x.Id); builder.Property(x => x.Id) .HasConversion(); builder.Property(x => x.DateTime) .IsRequired(); builder.Property(x => x.Distance) .IsRequired(); builder.Property(x => x.Amount) .IsRequired(); builder.Property(x => x.IgnoreInCalculation) .IsRequired(); builder.Property(x => x.CarId) .IsRequired() .HasConversion(); builder.HasOne(x => x.Car) .WithMany(x => x.Consumptions); } }