Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using Microsoft.EntityFrameworkCore;
  2. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  3. using Minerva.Domain.Entities;
  4.  
  5. namespace Minerva.Infra.Data.Configurations
  6. {
  7.     public class PersonConfiguration : IEntityTypeConfiguration<Person>
  8.     {
  9.         public void Configure(EntityTypeBuilder<Person> builder)
  10.         {
  11.             builder.OwnsOne(o => o.Name,
  12.                 sa =>
  13.                 {
  14.                     sa.Property(p => p.FullName)
  15.                         .HasColumnName("FullName")
  16.                         .HasComputedColumnSql("CONCAT(FirstName, ' ', LastName) PERSISTED");
  17.  
  18.                     sa.Property(p => p.FirstName)
  19.                         .HasColumnName("FirstName")
  20.                         .HasMaxLength(50)
  21.                         .IsRequired();
  22.  
  23.                     sa.Property(p => p.LastName)
  24.                         .HasColumnName("LastName")
  25.                         .HasMaxLength(50)
  26.                         .IsRequired();
  27.                 });
  28.  
  29.             builder.OwnsOne(o => o.FiscalId,
  30.                 sa =>
  31.                 {
  32.                     sa.Property(p => p.Number)
  33.                         .HasColumnName("Number")
  34.                         .HasMaxLength(20)
  35.                         .IsRequired();
  36.                 });
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement