Files
vegasco/src/Vegasco.Server.Api/Consumptions/Consumption.cs
ThompsonNye c58f6fe364
All checks were successful
continuous-integration/drone/push Build is passing
Drop IgnoreInCalculation property
2025-06-22 11:07:02 +02:00

48 lines
1.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vegasco.Server.Api.Cars;
namespace Vegasco.Server.Api.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 CarId CarId { get; set; }
public virtual Car Car { get; set; } = null!;
}
public class ConsumptionTableConfiguration : IEntityTypeConfiguration<Consumption>
{
public void Configure(EntityTypeBuilder<Consumption> builder)
{
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion<ConsumptionId.EfCoreValueConverter>();
builder.Property(x => x.DateTime)
.IsRequired();
builder.Property(x => x.Distance)
.IsRequired();
builder.Property(x => x.Amount)
.IsRequired();
builder.Property(x => x.CarId)
.IsRequired()
.HasConversion<CarId.EfCoreValueConverter>();
builder.HasOne(x => x.Car)
.WithMany(x => x.Consumptions);
}
}