@@ -10,24 +10,25 @@ namespace NHibernate.Test.NHSpecificTest.NH750
10
10
public class ManyToManyThrowsForNotFoundFixture : BugTestCase
11
11
{
12
12
private int _id ;
13
+ private int _withTempalteId ;
13
14
14
15
protected override void OnSetUp ( )
15
16
{
16
- using ( var s = Sfi . OpenSession ( ) )
17
- using ( var t = s . BeginTransaction ( ) )
18
- {
19
- Device dv = new Device ( "Device ") ;
20
- Drive dr = new Drive ( "Drive" ) ;
21
- s . Save ( dr ) ;
22
- dv . DrivesNotIgnored . Add ( dr ) ;
17
+ using var s = Sfi . OpenSession ( ) ;
18
+ using var t = s . BeginTransaction ( ) ;
19
+ Device dv = new Device ( "Device" ) ;
20
+ Drive dr = new Drive ( "Drive ") ;
21
+ var withTempalte = new Device ( "Device With Device 2 template" ) { Template = dv } ;
22
+ s . Save ( dr ) ;
23
+ dv . DrivesNotIgnored . Add ( dr ) ;
23
24
24
- _id = ( int ) s . Save ( dv ) ;
25
- s . Flush ( ) ;
25
+ _id = ( int ) s . Save ( dv ) ;
26
+ _withTempalteId = ( int ) s . Save ( withTempalte ) ;
27
+ s . Flush ( ) ;
26
28
27
- s . Clear ( ) ;
28
- s . Delete ( dr ) ;
29
- t . Commit ( ) ;
30
- }
29
+ s . Clear ( ) ;
30
+ s . Delete ( dr ) ;
31
+ t . Commit ( ) ;
31
32
}
32
33
33
34
protected override void OnTearDown ( )
@@ -58,7 +59,18 @@ public void QueryOverFetch()
58
59
. Fetch ( SelectMode . Fetch , x => x . DrivesNotIgnored )
59
60
. Where ( Restrictions . IdEq ( _id ) )
60
61
. TransformUsing ( Transformers . DistinctRootEntity ) ;
61
- Assert . Throws < ObjectNotFoundException > ( ( ) => NHibernateUtil . Initialize ( queryOver . SingleOrDefault ( ) ) ) ;
62
+ Assert . Throws < ObjectNotFoundException > ( ( ) => queryOver . SingleOrDefault ( ) ) ;
63
+ }
64
+
65
+ [ Test ]
66
+ public void QueryOverFetch2 ( )
67
+ {
68
+ using var s = OpenSession ( ) ;
69
+ var queryOver = s . QueryOver < Device > ( )
70
+ . Fetch ( SelectMode . Fetch , x=> x . Template , x => x . Template . DrivesNotIgnored )
71
+ . Where ( Restrictions . IdEq ( _withTempalteId ) )
72
+ . TransformUsing ( Transformers . DistinctRootEntity ) ;
73
+ Assert . Throws < ObjectNotFoundException > ( ( ) => queryOver . SingleOrDefault ( ) ) ;
62
74
}
63
75
64
76
[ Test ]
@@ -71,5 +83,17 @@ public void LinqFetch()
71
83
. Where ( x => x . Id == _id ) ;
72
84
Assert . Throws < ObjectNotFoundException > ( ( ) => NHibernateUtil . Initialize ( query . SingleOrDefault ( ) ) ) ;
73
85
}
86
+
87
+ [ Test ]
88
+ public void LinqFetch2 ( )
89
+ {
90
+ using var s = OpenSession ( ) ;
91
+ var query = s . Query < Device > ( )
92
+
93
+ . Fetch ( x => x . Template )
94
+ . ThenFetchMany ( x => x . DrivesNotIgnored )
95
+ . Where ( x => x . Id == _withTempalteId ) ;
96
+ Assert . Throws < ObjectNotFoundException > ( ( ) => NHibernateUtil . Initialize ( query . SingleOrDefault ( ) ) ) ;
97
+ }
74
98
}
75
99
}
0 commit comments