@@ -14,11 +14,18 @@ public abstract class Step
1414        public  string  Name  {  get ;  set ;  } 
1515        public  int  StepGroupId  {  get ;  set ;  } 
1616        public  virtual  StepGroup  StepGroup  {  get ;  set ;  } 
17+         public  virtual  ICollection < StepInput >  StepInputs  {  get ;  set ;  }  =  new  HashSet < StepInput > ( ) ; 
1718    } 
1819    public  class  CheckingStep  :  Step  {  } 
1920    public  class  InstructionStep  :  Step  {  } 
2021    public  abstract  class  AbstractStep  :  Step  {  } 
21- 
22+     public  class  StepInput 
23+     { 
24+         public  int  Id  {  get ;  set ;  } 
25+         public  int  StepId  {  get ;  set ;  } 
26+         public  string  Input  {  get ;  set ;  } 
27+         public  virtual  Step  Step  {  get ;  set ;  } 
28+     } 
2229    public  class  StepGroupModel 
2330    { 
2431        public  int  Id  {  get ;  set ;  } 
@@ -29,17 +36,27 @@ public abstract class StepModel
2936    { 
3037        public  int  Id  {  get ;  set ;  } 
3138        public  string  Name  {  get ;  set ;  } 
39+         public  ICollection < StepInputModel >  StepInputs  {  get ;  set ;  }  =  new  HashSet < StepInputModel > ( ) ; 
3240    } 
3341    public  class  CheckingStepModel  :  StepModel  {  } 
3442    public  class  InstructionStepModel  :  StepModel  {  } 
3543    public  abstract  class  AbstractStepModel  :  StepModel  {  } 
44+     public  class  StepInputModel 
45+     { 
46+         public  int  Id  {  get ;  set ;  } 
47+         public  int  StepId  {  get ;  set ;  } 
48+         public  string  Input  {  get ;  set ;  } 
49+         public  StepModel  Step  {  get ;  set ;  } 
50+     } 
3651
3752    public  class  Context  :  LocalDbContext 
3853    { 
3954        public  DbSet < StepGroup >  StepGroups  {  get ;  set ;  } 
4055
4156        public  DbSet < Step >  Steps  {  get ;  set ;  } 
4257
58+         public  DbSet < StepInput >  StepInputs  {  get ;  set ;  } 
59+ 
4360        public  DbSet < CheckingStep >  CheckingSteps  {  get ;  set ;  } 
4461
4562        public  DbSet < InstructionStep >  InstructionSteps  {  get ;  set ;  } 
@@ -51,6 +68,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
5168                entity . HasOne ( d =>  d . StepGroup ) . WithMany ( p =>  p . Steps ) 
5269                    . HasForeignKey ( d =>  d . StepGroupId ) ; 
5370            } ) ; 
71+ 
72+             modelBuilder . Entity < StepInput > ( entity => 
73+             { 
74+                 entity . HasOne ( d =>  d . Step ) . WithMany ( p =>  p . StepInputs ) 
75+                     . HasForeignKey ( d =>  d . StepId ) ; 
76+             } ) ; 
5477        } 
5578    } 
5679
@@ -66,6 +89,7 @@ protected override MapperConfiguration CreateConfiguration()
6689                . IncludeBase < Step ,  StepModel > ( ) ; 
6790            cfg . CreateMap < AbstractStep ,  AbstractStepModel > ( ) 
6891                . IncludeBase < Step ,  StepModel > ( ) ; 
92+             cfg . CreateMap < StepInput ,  StepInputModel > ( ) ; 
6993        } ) ; 
7094    } 
7195
@@ -80,7 +104,14 @@ protected override void Seed(Context context)
80104                { 
81105                    new  InstructionStep 
82106                    { 
83-                         Name  =  "InstructionStep" 
107+                         Name  =  "InstructionStep" , 
108+                         StepInputs  =  new  List < StepInput > 
109+                         { 
110+                             new  StepInput 
111+                             { 
112+                                 Input  =  "Input" 
113+                             } 
114+                         } 
84115                    } , 
85116                    new  CheckingStep 
86117                    { 
@@ -101,4 +132,12 @@ public void ProjectCollectionWithElementInheritingAbstractClass()
101132        steps [ 0 ] . ShouldBeOfType < CheckingStepModel > ( ) . Name . ShouldBe ( "CheckingStep" ) ; 
102133        steps [ 1 ] . ShouldBeOfType < InstructionStepModel > ( ) . Name . ShouldBe ( "InstructionStep" ) ; 
103134    } 
135+ 
136+     [ Fact ] 
137+     public  void  ProjectIncludingPolymorphicElement ( ) 
138+     { 
139+         using  var  context  =  new  Context ( ) ; 
140+         var  stepInput  =  ProjectTo < StepInputModel > ( context . StepInputs ) . Single ( ) ; 
141+         stepInput . Step . ShouldBeOfType < InstructionStepModel > ( ) . Name . ShouldBe ( "InstructionStep" ) ; 
142+     } 
104143} 
0 commit comments