File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
tests/Ardalis.Specification.EntityFrameworkCore.Tests Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,26 @@ public void QueriesMatch_GivenIncludeExpressions()
2929 actual . Should ( ) . Be ( expected ) ;
3030 }
3131
32+ [ Fact ]
33+ public void QueriesMatch_GivenInheritanceModel ( )
34+ {
35+ var spec = new Specification < Bar > ( ) ;
36+ spec . Query
37+ . Include ( x => x . BarChildren )
38+ . ThenInclude < Bar , BarChild , BarDerivedInfo > ( x => ( x as BarDerived ) ! . BarDerivedInfo ) ;
39+
40+ var actual = _evaluator
41+ . GetQuery ( DbContext . Bars , spec )
42+ . ToQueryString ( ) ;
43+
44+ var expected = DbContext . Bars
45+ . Include ( x => x . BarChildren )
46+ . ThenInclude ( x => ( x as BarDerived ) ! . BarDerivedInfo )
47+ . ToQueryString ( ) ;
48+
49+ actual . Should ( ) . Be ( expected ) ;
50+ }
51+
3252 [ Fact ]
3353 public void QueriesMatch_GivenThenIncludeWithVariousNavigationCollectionTypes ( )
3454 {
Original file line number Diff line number Diff line change 1+ namespace Tests . Fixture ;
2+
3+ public class Bar
4+ {
5+ public int Id { get ; set ; }
6+ public string ? Dummy { get ; set ; }
7+
8+ private readonly List < BarChild > _barChildren = [ ] ;
9+ public IReadOnlyCollection < BarChild > BarChildren => _barChildren . AsReadOnly ( ) ;
10+ }
11+
12+ public class BarChild
13+ {
14+ public int Id { get ; set ; }
15+ public string ? Dummy { get ; set ; }
16+
17+ public int BarId { get ; set ; }
18+ public Bar Bar { get ; set ; } = default ! ;
19+ }
20+
21+ public class BarDerived : BarChild
22+ {
23+ public int BarDerivedInfoId { get ; set ; }
24+ public BarDerivedInfo BarDerivedInfo { get ; set ; } = default ! ;
25+ }
26+
27+ public class BarDerivedInfo
28+ {
29+ public int Id { get ; set ; }
30+ public string ? Name { get ; set ; }
31+ }
Original file line number Diff line number Diff line change 22
33public class TestDbContext ( DbContextOptions options ) : DbContext ( options )
44{
5+ public DbSet < Bar > Bars => Set < Bar > ( ) ;
56 public DbSet < Foo > Foos => Set < Foo > ( ) ;
67 public DbSet < Country > Countries => Set < Country > ( ) ;
78 public DbSet < Company > Companies => Set < Company > ( ) ;
@@ -23,5 +24,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2324
2425 modelBuilder . Entity < Country > ( )
2526 . HasQueryFilter ( x => ! x . IsDeleted ) ;
27+
28+ modelBuilder . Entity < BarDerived > ( )
29+ . HasBaseType < BarChild > ( ) ;
2630 }
2731}
You can’t perform that action at this time.
0 commit comments