@@ -46,17 +46,29 @@ protected override void OnSetUp()
46
46
} ;
47
47
session . Save ( e2 ) ;
48
48
49
- var cachedConnection = new Connection
49
+ var cachedNullConnection = new Connection
50
50
{
51
51
Address = "test.com" ,
52
52
ConnectionType = "http" ,
53
53
} ;
54
- var cachedPerson = new CachedPerson
54
+ var cachedNullConnectionPerson = new CachedPerson
55
55
{
56
- Name = "Cached " ,
57
- Connection = cachedConnection
56
+ Name = "CachedNull " ,
57
+ Connection = cachedNullConnection
58
58
} ;
59
- session . Save ( cachedPerson ) ;
59
+ var cachedNotNullConnection = new Connection
60
+ {
61
+ Address = "test.com" ,
62
+ ConnectionType = "http" ,
63
+ PortName = "port"
64
+ } ;
65
+ var cachedNotNullConnectionPerson = new CachedPerson
66
+ {
67
+ Name = "CachedNotNull" ,
68
+ Connection = cachedNotNullConnection
69
+ } ;
70
+ session . Save ( cachedNullConnectionPerson ) ;
71
+ session . Save ( cachedNotNullConnectionPerson ) ;
60
72
61
73
session . Flush ( ) ;
62
74
transaction . Commit ( ) ;
@@ -145,6 +157,100 @@ public void QueryAgainstComponentWithANullPropertyUsingCriteria()
145
157
}
146
158
}
147
159
160
+ [ Test ]
161
+ public void CachedQueryMissesWithDifferentNotNullComponent ( )
162
+ {
163
+ var componentToCompare = new Connection
164
+ {
165
+ ConnectionType = "http" ,
166
+ Address = "test.com" ,
167
+ PortName = null
168
+ } ;
169
+
170
+ using ( ISession session = OpenSession ( ) )
171
+ using ( ITransaction tx = session . BeginTransaction ( ) )
172
+ {
173
+ var cached = session . CreateCriteria < CachedPerson > ( )
174
+ . Add ( Restrictions . Eq ( "Connection" , componentToCompare ) )
175
+ . SetCacheable ( true )
176
+ . UniqueResult < CachedPerson > ( ) ;
177
+
178
+ Assert . That ( cached . Name , Is . EqualTo ( "CachedNull" ) ) ;
179
+ Assert . That ( cached . Connection . PortName , Is . Null ) ;
180
+
181
+ using ( var dbCommand = session . Connection . CreateCommand ( ) )
182
+ {
183
+ dbCommand . CommandText = "DELETE FROM cachedpeople" ;
184
+ tx . Enlist ( dbCommand ) ;
185
+ dbCommand . ExecuteNonQuery ( ) ;
186
+ }
187
+
188
+ tx . Commit ( ) ;
189
+ }
190
+
191
+ componentToCompare . PortName = "port" ;
192
+ using ( ISession session = OpenSession ( ) )
193
+ using ( ITransaction tx = session . BeginTransaction ( ) )
194
+ {
195
+ //Cache should not return cached entity, because it no longer matches criteria
196
+ var cachedPeople = session . CreateCriteria < CachedPerson > ( )
197
+ . Add ( Restrictions . Eq ( "Connection" , componentToCompare ) )
198
+ . SetCacheable ( true )
199
+ . List < CachedPerson > ( ) ;
200
+
201
+ Assert . That ( cachedPeople , Is . Empty ) ;
202
+
203
+ tx . Commit ( ) ;
204
+ }
205
+ }
206
+
207
+ [ Test ]
208
+ public void CachedQueryMissesWithDifferentNullComponent ( )
209
+ {
210
+ var componentToCompare = new Connection
211
+ {
212
+ ConnectionType = "http" ,
213
+ Address = "test.com" ,
214
+ PortName = "port"
215
+ } ;
216
+
217
+ using ( ISession session = OpenSession ( ) )
218
+ using ( ITransaction tx = session . BeginTransaction ( ) )
219
+ {
220
+ var cached = session . CreateCriteria < CachedPerson > ( )
221
+ . Add ( Restrictions . Eq ( "Connection" , componentToCompare ) )
222
+ . SetCacheable ( true )
223
+ . UniqueResult < CachedPerson > ( ) ;
224
+
225
+ Assert . That ( cached . Name , Is . EqualTo ( "CachedNotNull" ) ) ;
226
+ Assert . That ( cached . Connection . PortName , Is . Not . Null ) ;
227
+
228
+ using ( var dbCommand = session . Connection . CreateCommand ( ) )
229
+ {
230
+ dbCommand . CommandText = "DELETE FROM cachedpeople" ;
231
+ tx . Enlist ( dbCommand ) ;
232
+ dbCommand . ExecuteNonQuery ( ) ;
233
+ }
234
+
235
+ tx . Commit ( ) ;
236
+ }
237
+
238
+ componentToCompare . PortName = null ;
239
+ using ( ISession session = OpenSession ( ) )
240
+ using ( ITransaction tx = session . BeginTransaction ( ) )
241
+ {
242
+ //Cache should not return cached entity, because it no longer matches criteria
243
+ var cachedPeople = session . CreateCriteria < CachedPerson > ( )
244
+ . Add ( Restrictions . Eq ( "Connection" , componentToCompare ) )
245
+ . SetCacheable ( true )
246
+ . List < CachedPerson > ( ) ;
247
+
248
+ Assert . That ( cachedPeople , Is . Empty ) ;
249
+
250
+ tx . Commit ( ) ;
251
+ }
252
+ }
253
+
148
254
[ Test ]
149
255
public void CachedQueryAgainstComponentWithANullPropertyUsingCriteria ( )
150
256
{
@@ -163,7 +269,7 @@ public void CachedQueryAgainstComponentWithANullPropertyUsingCriteria()
163
269
. SetCacheable ( true )
164
270
. UniqueResult < CachedPerson > ( ) ;
165
271
166
- Assert . That ( cached . Name , Is . EqualTo ( "Cached " ) ) ;
272
+ Assert . That ( cached . Name , Is . EqualTo ( "CachedNull " ) ) ;
167
273
Assert . That ( cached . Connection . PortName , Is . Null ) ;
168
274
169
275
using ( var dbCommand = session . Connection . CreateCommand ( ) )
@@ -185,7 +291,7 @@ public void CachedQueryAgainstComponentWithANullPropertyUsingCriteria()
185
291
. SetCacheable ( true )
186
292
. UniqueResult < CachedPerson > ( ) ;
187
293
188
- Assert . That ( cached . Name , Is . EqualTo ( "Cached " ) ) ;
294
+ Assert . That ( cached . Name , Is . EqualTo ( "CachedNull " ) ) ;
189
295
Assert . That ( cached . Connection . PortName , Is . Null ) ;
190
296
191
297
tx . Commit ( ) ;
0 commit comments