@@ -395,6 +395,23 @@ public void SkipRootEntityIsNotSupportedAsync()
395
395
}
396
396
}
397
397
398
+ [ Test ]
399
+ public async Task OrderedInnerJoinFetchAsync ( )
400
+ {
401
+ using ( var session = OpenSession ( ) )
402
+ {
403
+ var list = await ( session . QueryOver < EntityComplex > ( )
404
+ . Where ( ec => ec . Id == _parentEntityComplexId )
405
+ . JoinQueryOver ( c => c . ChildrenList ) . Fetch ( SelectMode . Fetch , child => child )
406
+ . TransformUsing ( Transformers . DistinctRootEntity )
407
+ . ListAsync ( ) ) ;
408
+
409
+ var childList = list [ 0 ] . ChildrenList ;
410
+ Assert . That ( list [ 0 ] . ChildrenList . Count , Is . GreaterThan ( 1 ) ) ;
411
+ Assert . That ( list [ 0 ] . ChildrenList , Is . EqualTo ( list [ 0 ] . ChildrenList . OrderByDescending ( c => c . OrderIdx ) ) , "wrong order" ) ;
412
+ }
413
+ }
414
+
398
415
[ Test , Obsolete ]
399
416
public async Task FetchModeEagerForLazyAsync ( )
400
417
{
@@ -562,15 +579,19 @@ protected override HbmMapping GetMappings()
562
579
m . Column ( "SameTypeChildId" ) ;
563
580
m . ForeignKey ( "none" ) ;
564
581
} ) ;
565
- MapList ( rc , ep => ep . ChildrenList ) ;
582
+ MapList ( rc , ep => ep . ChildrenList , mapper : m => m . OrderBy ( "OrderIdx desc" ) ) ;
566
583
MapList ( rc , ep => ep . ChildrenListEmpty ) ;
567
584
} ) ;
568
585
569
586
MapSimpleChild (
570
587
mapper ,
571
588
default ( EntitySimpleChild ) ,
572
589
c => c . Children ,
573
- rc => { rc . Property ( sc => sc . LazyProp , mp => mp . Lazy ( true ) ) ; } ) ;
590
+ rc =>
591
+ {
592
+ rc . Property ( sc => sc . LazyProp , mp => mp . Lazy ( true ) ) ;
593
+ rc . Property ( sc => sc . OrderIdx ) ;
594
+ } ) ;
574
595
MapSimpleChild ( mapper , default ( Level2Child ) , c => c . Children ) ;
575
596
MapSimpleChild < Level3Child > ( mapper ) ;
576
597
@@ -598,7 +619,7 @@ private static void MapSimpleChild<TChild, TSubChild>(ModelMapper mapper, TChild
598
619
} ) ;
599
620
}
600
621
601
- private static void MapList < TParent , TElement > ( IClassMapper < TParent > rc , Expression < Func < TParent , IEnumerable < TElement > > > expression , CollectionFetchMode fetchMode = null ) where TParent : class
622
+ private static void MapList < TParent , TElement > ( IClassMapper < TParent > rc , Expression < Func < TParent , IEnumerable < TElement > > > expression , CollectionFetchMode fetchMode = null , Action < IBagPropertiesMapper < TParent , TElement > > mapper = null ) where TParent : class
602
623
{
603
624
rc . Bag (
604
625
expression ,
@@ -620,6 +641,7 @@ private static void MapList<TParent, TElement>(IClassMapper<TParent> rc, Express
620
641
{
621
642
m . Fetch ( fetchMode ) ;
622
643
}
644
+ mapper ? . Invoke ( m ) ;
623
645
} ,
624
646
a => a . OneToMany ( ) ) ;
625
647
}
@@ -682,7 +704,8 @@ protected override void OnSetUp()
682
704
} ,
683
705
}
684
706
}
685
- }
707
+ } ,
708
+ OrderIdx = 100
686
709
} ;
687
710
688
711
var child2 = new EntitySimpleChild
@@ -691,6 +714,17 @@ protected override void OnSetUp()
691
714
LazyProp = "LazyFromSimpleChild2" ,
692
715
} ;
693
716
717
+ var child3 = new EntitySimpleChild
718
+ {
719
+ Name = "Child3" ,
720
+ OrderIdx = 0
721
+ } ;
722
+ var child4 = new EntitySimpleChild
723
+ {
724
+ Name = "Child4" ,
725
+ OrderIdx = 50
726
+ } ;
727
+
694
728
var parent = new EntityComplex
695
729
{
696
730
Name = "ComplexEntityParent" ,
@@ -701,7 +735,7 @@ protected override void OnSetUp()
701
735
{
702
736
Name = "ComplexEntityChild"
703
737
} ,
704
- ChildrenList = new List < EntitySimpleChild > { child1 } ,
738
+ ChildrenList = new List < EntitySimpleChild > { child3 , child1 , child4 } ,
705
739
ChildrenListEmpty = new List < EntityComplex > { } ,
706
740
} ;
707
741
session . Save ( new EntityEager ( )
0 commit comments