CustomerMapping.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using GreenTree.Strohrmann.ERP.Core.Domain.Business;
  2. using Microsoft.EntityFrameworkCore;
  3. using Microsoft.EntityFrameworkCore.Metadata.Builders;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace GreenTree.Strohrmann.ERP.Domain.Model.Business
  8. {
  9. public class CustomerMapping : IEntityTypeConfiguration<Customer>
  10. {
  11. public void Configure(EntityTypeBuilder<Customer> builder)
  12. {
  13. builder.ToTable("Customers");
  14. builder.HasKey(u => u.Id);
  15. builder.Property(u => u.Id)
  16. .ValueGeneratedOnAdd();
  17. builder.Property(u => u.Firstname)
  18. .IsRequired();
  19. builder.Property(u => u.Lastname)
  20. .IsRequired();
  21. builder.Property(u => u.Address)
  22. .IsRequired();
  23. builder.Property(u => u.Town)
  24. .IsRequired();
  25. builder.Property(u => u.ZipCode)
  26. .IsRequired();
  27. builder.Property(u => u.Country)
  28. .IsRequired();
  29. builder.HasOne(u => u.Tax)
  30. .WithMany(d => d.Customers)
  31. .IsRequired()
  32. .OnDelete(DeleteBehavior.Restrict);
  33. }
  34. }
  35. }