Fixed configurations of owned types
This commit is contained in:
		| @@ -1,18 +1,23 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|  | ||||
| namespace Infrastructure.Database.Applicants.Configuration; | ||||
|  | ||||
| public class AddressConfiguration : IEntityTypeConfiguration<Address> | ||||
| public static class AddressConfiguration<T> where T : class, IEntity | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Address> entity) | ||||
|     public static void Configure(OwnedNavigationBuilder<T, Address> entity) | ||||
|     { | ||||
|         entity.HasOne(a => a.Country).WithMany().OnDelete(DeleteBehavior.Restrict); | ||||
|         entity.HasOne(a => a.City).WithMany().OnDelete(DeleteBehavior.Restrict); | ||||
|  | ||||
|         entity.Property(p => p.Street) | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(100); | ||||
|  | ||||
|         entity.Property(p => p.Building) | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(10); | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -9,11 +9,13 @@ public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant> | ||||
|     public void Configure(EntityTypeBuilder<Applicant> entity) | ||||
|     { | ||||
|         entity.ToTable("Applicants"); | ||||
|         entity.OwnsOne(p => p.Name, NameConfiguration<Applicant>.Configure); | ||||
|         entity.OwnsOne(p => p.FatherName, NameConfiguration<Applicant>.Configure); | ||||
|         entity.OwnsOne(p => p.MotherName, NameConfiguration<Applicant>.Configure); | ||||
|         entity.OwnsOne(p => p.Passport, PassportConfiguration<Applicant>.Configure); | ||||
|  | ||||
|         entity.OwnsOne(p => p.Name); | ||||
|         entity.OwnsOne(p => p.FatherName); | ||||
|         entity.OwnsOne(p => p.MotherName); | ||||
|         entity.OwnsOne(p => p.Passport); | ||||
|         entity.HasOne(a => a.CityOfBirth).WithMany().OnDelete(DeleteBehavior.Restrict); | ||||
|         entity.HasOne(a => a.CountryOfBirth).WithMany().OnDelete(DeleteBehavior.Restrict); | ||||
|  | ||||
|         entity.Property(p => p.Citizenship) | ||||
|             .IsUnicode(false) | ||||
| @@ -23,4 +25,4 @@ public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant> | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(30); | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -1,12 +1,12 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|  | ||||
| namespace Infrastructure.Database.Applicants.Configuration; | ||||
|  | ||||
| public class NameConfiguration : IEntityTypeConfiguration<Name> | ||||
| public static class NameConfiguration<T> where T : class, IEntity | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Name> entity) | ||||
|     public static void Configure(OwnedNavigationBuilder<T, Name> entity) | ||||
|     { | ||||
|         entity.Property(p => p.FirstName) | ||||
|             .IsUnicode(false) | ||||
| @@ -20,4 +20,4 @@ public class NameConfiguration : IEntityTypeConfiguration<Name> | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(50); | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -1,12 +1,12 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|  | ||||
| namespace Infrastructure.Database.Applicants.Configuration; | ||||
|  | ||||
| public class PassportConfiguration : IEntityTypeConfiguration<Passport> | ||||
| public static class PassportConfiguration<T> where T : class, IEntity | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<Passport> entity) | ||||
|     public static void Configure(OwnedNavigationBuilder<T, Passport> entity) | ||||
|     { | ||||
|         entity.Property(p => p.Number) | ||||
|             .IsUnicode(false) | ||||
| @@ -16,4 +16,4 @@ public class PassportConfiguration : IEntityTypeConfiguration<Passport> | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(200); | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -8,7 +8,7 @@ public class PlaceOfWorkConfiguration : IEntityTypeConfiguration<PlaceOfWork> | ||||
| { | ||||
|     public void Configure(EntityTypeBuilder<PlaceOfWork> entity) | ||||
|     { | ||||
|         entity.OwnsOne(p => p.Address); | ||||
|         entity.OwnsOne(p => p.Address, AddressConfiguration<PlaceOfWork>.Configure); | ||||
|  | ||||
|         entity.Property(p => p.Name) | ||||
|             .IsUnicode(false) | ||||
| @@ -18,4 +18,4 @@ public class PlaceOfWorkConfiguration : IEntityTypeConfiguration<PlaceOfWork> | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(20); | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| using ApplicationLayer.Applicants; | ||||
| using ApplicationLayer.Applicants.NeededServices; | ||||
| using Domains.ApplicantDomain; | ||||
| using Infrastructure.Database.Generic; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user