1- using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products ;
2- using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products . Backpacks ;
3- using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products . Boots ;
4- using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products . Kayaks ;
5- using Dotnet5 . GraphQL3 . Store . Domain . Enumerations ;
6- using Microsoft . EntityFrameworkCore ;
7- using Microsoft . EntityFrameworkCore . Metadata . Builders ;
8- using Microsoft . EntityFrameworkCore . Storage . ValueConversion ;
9-
10- namespace Dotnet5 . GraphQL3 . Store . Repositories . Configs . Products
11- {
12- public class ProductConfig : IEntityTypeConfiguration < Product >
13- {
14- private const string DiscriminatorDefaultName = "Discriminator" ;
15-
16- public void Configure ( EntityTypeBuilder < Product > builder )
17- {
18- builder
19- . HasKey ( x => x . Id ) ;
20-
21- builder
22- . Property ( x => x . Description )
23- . HasMaxLength ( 300 ) ;
24-
25- builder
26- . Property ( x => x . IntroduceAt ) ;
27-
28- builder
29- . Property ( x => x . Name )
30- . HasMaxLength ( 50 )
31- . IsRequired ( ) ;
32-
33- builder
34- . Property ( x => x . PhotoUrl )
35- . HasMaxLength ( 100 ) ;
36-
37- builder
38- . Property ( x => x . Price )
39- . HasPrecision ( 18 , 2 )
40- . IsRequired ( ) ;
41-
42- builder
43- . Property ( x => x . Option )
44- . HasConversion ( new EnumToStringConverter < Option > ( ) ) ;
45-
46- builder
47- . Property ( x => x . Rating ) ;
48-
49- builder
50- . Property ( x => x . Stock ) ;
51-
52- builder
53- . HasOne ( x => x . ProductType ) ;
54-
55- builder
56- . HasMany ( x => x . Reviews )
57- . WithOne ( x => x . Product )
58- . HasForeignKey ( x => x . ProductId ) ;
59-
60- builder
61- . HasDiscriminator ( )
62- . HasValue < Boot > ( nameof ( Boot ) )
63- . HasValue < Kayak > ( nameof ( Kayak ) )
64- . HasValue < Backpack > ( nameof ( Backpack ) ) ;
65-
66- builder
67- . Property ( DiscriminatorDefaultName )
68- . HasMaxLength ( 30 ) ;
69- }
70- }
1+ using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products ;
2+ using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products . Backpacks ;
3+ using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products . Boots ;
4+ using Dotnet5 . GraphQL3 . Store . Domain . Entities . Products . Kayaks ;
5+ using Dotnet5 . GraphQL3 . Store . Domain . Enumerations ;
6+ using Microsoft . EntityFrameworkCore ;
7+ using Microsoft . EntityFrameworkCore . Metadata . Builders ;
8+ using Microsoft . EntityFrameworkCore . Storage . ValueConversion ;
9+
10+ namespace Dotnet5 . GraphQL3 . Store . Repositories . Configurations . Products
11+ {
12+ public class ProductConfiguration : IEntityTypeConfiguration < Product >
13+ {
14+ private const string DiscriminatorDefaultName = "Discriminator" ;
15+
16+ public void Configure ( EntityTypeBuilder < Product > builder )
17+ {
18+ builder
19+ . HasKey ( x => x . Id ) ;
20+
21+ builder
22+ . Property ( x => x . Description )
23+ . HasMaxLength ( 300 ) ;
24+
25+ builder
26+ . Property ( x => x . IntroduceAt ) ;
27+
28+ builder
29+ . Property ( x => x . Name )
30+ . HasMaxLength ( 50 )
31+ . IsRequired ( ) ;
32+
33+ builder
34+ . Property ( x => x . PhotoUrl )
35+ . HasMaxLength ( 100 ) ;
36+
37+ builder
38+ . Property ( x => x . Price )
39+ . HasPrecision ( 10 , 2 )
40+ . IsRequired ( ) ;
41+
42+ builder
43+ . Property ( x => x . Option )
44+ . HasConversion ( new EnumToStringConverter < Option > ( ) ) ;
45+
46+ builder
47+ . Property ( x => x . Rating ) ;
48+
49+ builder
50+ . Property ( x => x . Stock ) ;
51+
52+ builder
53+ . HasOne ( x => x . ProductType ) ;
54+
55+ builder
56+ . HasMany ( x => x . Reviews )
57+ . WithOne ( x => x . Product )
58+ . HasForeignKey ( x => x . ProductId ) ;
59+
60+ builder
61+ . HasDiscriminator ( )
62+ . HasValue < Boot > ( nameof ( Boot ) )
63+ ? . HasValue < Kayak > ( nameof ( Kayak ) )
64+ ? . HasValue < Backpack > ( nameof ( Backpack ) ) ;
65+
66+ builder
67+ . Property ( DiscriminatorDefaultName )
68+ . HasMaxLength ( 30 ) ;
69+ }
70+ }
7171}
0 commit comments