6
6
7
7
namespace NHibernate . Test . NHSpecificTest . CachingComplexQuery
8
8
{
9
- /// <summary>
10
- /// Fixture using 'by code' mappings
11
- /// </summary>
12
- /// <remarks>
13
- /// This fixture is identical to <see cref="Fixture" /> except the <see cref="Person" /> mapping is performed
14
- /// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach
15
- /// if you prefer.
16
- /// </remarks>
17
9
[ TestFixture ]
18
10
public class ByCodeFixture : TestCaseMappingByCode
19
11
{
@@ -94,7 +86,7 @@ protected override void OnSetUp()
94
86
var car2 = new Car { Name = "Car2" , Owner = person } ;
95
87
session . Save ( car1 ) ;
96
88
session . Save ( car2 ) ;
97
-
89
+
98
90
session . Save ( person ) ;
99
91
transaction . Commit ( ) ;
100
92
}
@@ -105,11 +97,10 @@ protected override void OnTearDown()
105
97
using ( var session = OpenSession ( ) )
106
98
using ( var transaction = session . BeginTransaction ( ) )
107
99
{
108
- session . Delete ( "from Pet" ) ;
109
- session . Delete ( "from Child" ) ;
110
- session . Delete ( "from Car" ) ;
111
- session . Delete ( "from Person" ) ;
112
-
100
+ session . CreateQuery ( "delete from Pet" ) . ExecuteUpdate ( ) ;
101
+ session . CreateQuery ( "delete from Child" ) . ExecuteUpdate ( ) ;
102
+ session . CreateQuery ( "delete from Car" ) . ExecuteUpdate ( ) ;
103
+ session . CreateQuery ( "delete from Person" ) . ExecuteUpdate ( ) ;
113
104
transaction . Commit ( ) ;
114
105
}
115
106
}
@@ -118,25 +109,23 @@ protected override void OnTearDown()
118
109
public void TestQueryCachingWithThenFetchMany ( )
119
110
{
120
111
using ( var session = OpenSession ( ) )
112
+ using ( var transaction = session . BeginTransaction ( ) )
121
113
{
122
- using ( var transaction = session . BeginTransaction ( ) )
123
- {
124
- var query =
125
- session
126
- . Query < Person > ( )
127
- . FetchMany ( p => p . Children )
128
- . ThenFetchMany ( ch => ch . Pets )
129
- . FetchMany ( p => p . Cars ) as IQueryable < Person > ;
114
+ var query =
115
+ session
116
+ . Query < Person > ( )
117
+ . FetchMany ( p => p . Children )
118
+ . ThenFetchMany ( ch => ch . Pets )
119
+ . FetchMany ( p => p . Cars ) as IQueryable < Person > ;
130
120
131
- query = query . WithOptions ( opt =>
132
- opt . SetCacheable ( true )
133
- . SetCacheMode ( CacheMode . Normal )
134
- . SetCacheRegion ( "Long_Cache" ) ) ;
121
+ query = query . WithOptions ( opt =>
122
+ opt . SetCacheable ( true )
123
+ . SetCacheMode ( CacheMode . Normal )
124
+ . SetCacheRegion ( "Long_Cache" ) ) ;
135
125
136
- query . ToList ( ) ; // First time the result will be cached
137
- Assert . That ( ( ) => query . ToList ( ) , Throws . Nothing ) ; //
138
- transaction . Commit ( ) ;
139
- }
126
+ query . ToList ( ) ; // First time the result will be cached
127
+ Assert . That ( ( ) => query . ToList ( ) , Throws . Nothing ) ;
128
+ transaction . Commit ( ) ;
140
129
}
141
130
}
142
131
}
0 commit comments