Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.CompilerServices;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.EntityFrameworkCore.Metadata.Builders;
- using VinylStore.Catalog.Domain.Entities;
- namespace VinylStore.Catalog.Infrastructure.SchemaDefinitions
- {
- public class ItemEntitySchemaDefinition : IEntityTypeConfiguration<Item>
- {
- public void Configure(EntityTypeBuilder<Item> builder)
- {
- builder.ToTable("Items", CatalogContext.DEFAULT_SCHEMA);
- builder.HasKey(it => it.Id);
- builder.Property(x => x.Name)
- .IsRequired();
- builder.Property(x => x.Description)
- .IsRequired()
- .HasMaxLength(1000);
- builder.OwnsOne(root => root.Artist, b =>
- {
- b.WithOwner()
- .HasForeignKey(e => e.ArtistId);
- });
- builder.OwnsOne(root => root.Genre, b =>
- {
- b.WithOwner()
- .HasForeignKey(e => e.GenreId);
- });
- builder.OwnsOne(root => root.Price);
- builder.Property(x => x.Price).HasConversion(
- x => $"{x.Amount}:{x.Currency}",
- x => new Money
- {
- Amount = Convert.ToDecimal(x.Split(':', StringSplitOptions.None)[0]),
- Currency = x.Split(':', StringSplitOptions.None)[1]
- });
- }
- public class ArtistEntitySchemaConfiguration : IEntityTypeConfiguration<Artist>
- {
- public void Configure(EntityTypeBuilder<Artist> builder)
- {
- builder.ToTable("Artists", CatalogContext.DEFAULT_SCHEMA);
- builder.HasKey(x => x.ArtistId);
- builder.Property(x => x.ArtistId);
- builder.Property(x => x.ArtistName)
- .IsRequired()
- .HasMaxLength(200);
- builder.HasMany(navigation => navigation.Items);
- }
- }
- public class GenreEntitySchemaConfiguration : IEntityTypeConfiguration<Genre>
- {
- public void Configure(EntityTypeBuilder<Genre> builder)
- {
- builder.ToTable("Genres", CatalogContext.DEFAULT_SCHEMA);
- builder.HasKey(x => x.GenreId);
- builder.Property(x => x.GenreId);
- builder.Property(x => x.GenreDescription)
- .IsRequired()
- .HasMaxLength(1000);
- builder.HasMany(navigation => navigation.Items);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement