Add consumption entity and use strongly typed ids
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user