Add consumption entity and use strongly typed ids

This commit is contained in:
2024-08-17 18:00:23 +02:00
parent 4bfc57ef9f
commit d47e4c1971
19 changed files with 265 additions and 36 deletions

View File

@@ -1,18 +1,21 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Vegasco.WebApi.Consumptions;
using Vegasco.WebApi.Users;
namespace Vegasco.WebApi.Cars;
public class Car
{
public Guid Id { get; set; } = Guid.NewGuid();
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<Consumption> Consumptions { get; set; } = [];
}
public class CarTableConfiguration : IEntityTypeConfiguration<Car>
@@ -23,6 +26,9 @@ public class CarTableConfiguration : IEntityTypeConfiguration<Car>
{
builder.HasKey(x => x.Id);
builder.Property(x => x.Id)
.HasConversion<CarId.EfCoreValueConverter>();
builder.Property(x => x.Name)
.IsRequired()
.HasMaxLength(NameMaxLength);