diff --git a/src/IntegrationTests/Inheritance/ProjectToAbstractTypeWithInheritance.cs b/src/IntegrationTests/Inheritance/ProjectToAbstractTypeWithInheritance.cs index 4c8535a29e..ef80014b7e 100644 --- a/src/IntegrationTests/Inheritance/ProjectToAbstractTypeWithInheritance.cs +++ b/src/IntegrationTests/Inheritance/ProjectToAbstractTypeWithInheritance.cs @@ -14,11 +14,18 @@ public abstract class Step public string Name { get; set; } public int StepGroupId { get; set; } public virtual StepGroup StepGroup { get; set; } + public virtual ICollection StepInputs { get; set; } = new HashSet(); } public class CheckingStep : Step { } public class InstructionStep : Step { } public abstract class AbstractStep : Step { } - + public class StepInput + { + public int Id { get; set; } + public int StepId { get; set; } + public string Input { get; set; } + public virtual Step Step { get; set; } + } public class StepGroupModel { public int Id { get; set; } @@ -29,10 +36,18 @@ public abstract class StepModel { public int Id { get; set; } public string Name { get; set; } + public ICollection StepInputs { get; set; } = new HashSet(); } public class CheckingStepModel : StepModel { } public class InstructionStepModel : StepModel { } public abstract class AbstractStepModel : StepModel { } + public class StepInputModel + { + public int Id { get; set; } + public int StepId { get; set; } + public string Input { get; set; } + public StepModel Step { get; set; } + } public class Context : LocalDbContext { @@ -40,6 +55,8 @@ public class Context : LocalDbContext public DbSet Steps { get; set; } + public DbSet StepInputs { get; set; } + public DbSet CheckingSteps { get; set; } public DbSet InstructionSteps { get; set; } @@ -51,6 +68,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.HasOne(d => d.StepGroup).WithMany(p => p.Steps) .HasForeignKey(d => d.StepGroupId); }); + + modelBuilder.Entity(entity => + { + entity.HasOne(d => d.Step).WithMany(p => p.StepInputs) + .HasForeignKey(d => d.StepId); + }); } } @@ -66,6 +89,7 @@ protected override MapperConfiguration CreateConfiguration() .IncludeBase(); cfg.CreateMap() .IncludeBase(); + cfg.CreateMap(); }); } @@ -80,7 +104,14 @@ protected override void Seed(Context context) { new InstructionStep { - Name = "InstructionStep" + Name = "InstructionStep", + StepInputs = new List + { + new StepInput + { + Input = "Input" + } + } }, new CheckingStep { @@ -101,4 +132,12 @@ public void ProjectCollectionWithElementInheritingAbstractClass() steps[0].ShouldBeOfType().Name.ShouldBe("CheckingStep"); steps[1].ShouldBeOfType().Name.ShouldBe("InstructionStep"); } + + [Fact] + public void ProjectIncludingPolymorphicElement() + { + using var context = new Context(); + var stepInput = ProjectTo(context.StepInputs).Single(); + stepInput.Step.ShouldBeOfType().Name.ShouldBe("InstructionStep"); + } } \ No newline at end of file