53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
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<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.IgnoreInCalculation)
|
|
.IsRequired();
|
|
|
|
builder.Property(x => x.CarId)
|
|
.IsRequired()
|
|
.HasConversion<CarId.EfCoreValueConverter>();
|
|
|
|
builder.HasOne(x => x.Car)
|
|
.WithMany(x => x.Consumptions);
|
|
}
|
|
}
|