mirror of
https://github.com/farcasclaudiu/PracticeCalendar.git
synced 2026-06-28 13:01:04 +03:00
play with storing valueobjects
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PracticeCalendar.Domain.Common;
|
||||
using PracticeCalendar.Domain.Common.Interfaces;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
using PracticeCalendar.Domain.Entities.PracticeEvent;
|
||||
using PracticeCalendar.Domain.Entities.Product;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PracticeCalendar.Infrastructure.Persistence
|
||||
@@ -13,6 +14,8 @@ namespace PracticeCalendar.Infrastructure.Persistence
|
||||
public DbSet<Attendee> Atendees => Set<Attendee>();
|
||||
public DbSet<PracticeEvent> PracticeEvents => Set<PracticeEvent>();
|
||||
|
||||
public DbSet<Product> Products => Set<Product>();
|
||||
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IDomainEventService domainEventService)
|
||||
: base(options)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PracticeCalendar.Domain.Entities.PracticeEvent;
|
||||
|
||||
namespace PracticeCalendar.Infrastructure.Persistence
|
||||
{
|
||||
@@ -14,7 +9,7 @@ namespace PracticeCalendar.Infrastructure.Persistence
|
||||
private readonly ILogger<ApplicationDbContextInitialiser> logger;
|
||||
private readonly ApplicationDbContext context;
|
||||
|
||||
public ApplicationDbContextInitialiser(ILogger<ApplicationDbContextInitialiser> logger,
|
||||
public ApplicationDbContextInitialiser(ILogger<ApplicationDbContextInitialiser> logger,
|
||||
ApplicationDbContext context)
|
||||
{
|
||||
this.logger = logger;
|
||||
@@ -27,6 +22,7 @@ namespace PracticeCalendar.Infrastructure.Persistence
|
||||
{
|
||||
if (context.Database.IsSqlite())
|
||||
{
|
||||
await context.Database.EnsureCreatedAsync();
|
||||
await context.Database.MigrateAsync();
|
||||
}
|
||||
}
|
||||
@@ -56,7 +52,7 @@ namespace PracticeCalendar.Infrastructure.Persistence
|
||||
// Seed, if necessary
|
||||
if (!context.PracticeEvents.Any())
|
||||
{
|
||||
context.PracticeEvents.Add(new PracticeEvent("Event 1", "Event 1 desc",
|
||||
context.PracticeEvents.Add(new PracticeEvent("Event 1", "Event 1 desc",
|
||||
DateTime.Now.AddHours(-1),
|
||||
DateTime.Now.AddHours(1)));
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
using PracticeCalendar.Domain.Entities.PracticeEvent;
|
||||
|
||||
namespace PracticeCalendar.Infrastructure.Persistence.Configuration
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
using PracticeCalendar.Domain.Entities.PracticeEvent;
|
||||
|
||||
namespace PracticeCalendar.Infrastructure.Persistence.Configuration
|
||||
{
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using PracticeCalendar.Domain.Entities.Product;
|
||||
using PracticeCalendar.Domain.ValueObjects;
|
||||
|
||||
namespace PracticeCalendar.Infrastructure.Persistence.Configuration
|
||||
{
|
||||
public class ProductConfiguration : IEntityTypeConfiguration<Product>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Product> builder)
|
||||
{
|
||||
builder.Property(x => x.Name)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.Category)
|
||||
.HasMaxLength(100)
|
||||
.IsRequired();
|
||||
builder.OwnsOne(product => product.UnitPrice, price =>
|
||||
{
|
||||
price.Property(p => p.Currency)
|
||||
.HasColumnName(nameof(Price.Currency))
|
||||
.HasMaxLength(5)
|
||||
.IsRequired();
|
||||
price.Property(p => p.Value)
|
||||
.HasColumnName(nameof(Price.Value))
|
||||
.IsRequired();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user