forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIQueryOver.cs
517 lines (445 loc) · 21.3 KB
/
IQueryOver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using NHibernate.Criterion;
using NHibernate.Criterion.Lambda;
using NHibernate.SqlCommand;
namespace NHibernate
{
public interface IQueryOver
{
/// <summary>
/// Access the underlying ICriteria
/// </summary>
ICriteria UnderlyingCriteria { get; }
/// <summary>
/// Access the root underlying ICriteria
/// </summary>
ICriteria RootCriteria { get; }
}
/// <summary>
/// QueryOver<TRoot> is an API for retrieving entities by composing
/// <see cref="Criterion.Expression" /> objects expressed using Lambda expression syntax.
/// </summary>
/// <remarks>
/// <code>
/// IList<Cat> cats = session.QueryOver<Cat>()
/// .Where( c => c.Name == "Tigger" )
/// .And( c => c.Weight > minWeight ) )
/// .List();
/// </code>
/// </remarks>
public interface IQueryOver<TRoot> : IQueryOver
{
/// <summary>
/// Get the results of the root type and fill the <see cref="IList<T>"/>
/// </summary>
/// <returns>The list filled with the results.</returns>
IList<TRoot> List();
/// <summary>
/// Get the results of the root type and fill the <see cref="IList<T>"/>
/// </summary>
/// <returns>The list filled with the results.</returns>
IList<U> List<U>();
/// <summary>
/// Clones the QueryOver, removes orders and paging, and projects the row-count
/// for the query
/// </summary>
IQueryOver<TRoot,TRoot> ToRowCountQuery();
/// <summary>
/// Short for ToRowCountQuery().SingleOrDefault()
/// </summary>
int RowCount();
/// <summary>
/// Convenience method to return a single instance that matches
/// the query, or null if the query returns no results.
/// </summary>
/// <returns>the single result or <see langword="null" /></returns>
/// <exception cref="HibernateException">
/// If there is more than one matching result
/// </exception>
TRoot SingleOrDefault();
/// <summary>
/// Override type of <see cref="SingleOrDefault()" />.
/// </summary>
U SingleOrDefault<U>();
/// <summary>
/// Get a enumerable that when enumerated will execute
/// a batch of queries in a single database roundtrip
/// </summary>
IEnumerable<TRoot> Future();
/// <summary>
/// Get a enumerable that when enumerated will execute
/// a batch of queries in a single database roundtrip
/// </summary>
IEnumerable<U> Future<U>();
/// <summary>
/// Get an IFutureValue instance, whose value can be retrieved through
/// its Value property. The query is not executed until the Value property
/// is retrieved, which will execute other Future queries as well in a
/// single roundtrip
/// </summary>
IFutureValue<TRoot> FutureValue();
/// <summary>
/// Get an IFutureValue instance, whose value can be retrieved through
/// its Value property. The query is not executed until the Value property
/// is retrieved, which will execute other Future queries as well in a
/// single roundtrip
/// </summary>
IFutureValue<U> FutureValue<U>();
/// <summary>
/// Creates an exact clone of the IQueryOver
/// </summary>
IQueryOver<TRoot,TRoot> Clone();
}
/// <summary>
/// QueryOver<TRoot,TSubType> is an API for retrieving entities by composing
/// <see cref="Criterion.Expression" /> objects expressed using Lambda expression syntax.
/// </summary>
/// <remarks>
/// <code>
/// IList<Cat> cats = session.QueryOver<Cat>()
/// .Where( c => c.Name == "Tigger" )
/// .And( c => c.Weight > minWeight ) )
/// .List();
/// </code>
/// </remarks>
public interface IQueryOver<TRoot,TSubType> : IQueryOver<TRoot>
{
/// <summary>
/// Add criterion expressed as a lambda expression
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> And(Expression<Func<TSubType, bool>> expression);
/// <summary>
/// Add criterion expressed as a lambda expression
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> And(Expression<Func<bool>> expression);
/// <summary>
/// Add arbitrary ICriterion (e.g., to allow protected member access)
/// </summary>
IQueryOver<TRoot,TSubType> And(ICriterion expression);
/// <summary>
/// Add negation of criterion expressed as a lambda expression
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> AndNot(Expression<Func<TSubType, bool>> expression);
/// <summary>
/// Add negation of criterion expressed as a lambda expression
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> AndNot(Expression<Func<bool>> expression);
/// <summary>
/// Add restriction to a property
/// </summary>
/// <param name="expression">Lambda expression containing path to property</param>
/// <returns>criteria instance</returns>
IQueryOverRestrictionBuilder<TRoot,TSubType> AndRestrictionOn(Expression<Func<TSubType, object>> expression);
/// <summary>
/// Add restriction to a property
/// </summary>
/// <param name="expression">Lambda expression containing path to property</param>
/// <returns>criteria instance</returns>
IQueryOverRestrictionBuilder<TRoot,TSubType> AndRestrictionOn(Expression<Func<object>> expression);
/// <summary>
/// Identical semantics to And() to allow more readable queries
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> Where(Expression<Func<TSubType, bool>> expression);
/// <summary>
/// Identical semantics to And() to allow more readable queries
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> Where(Expression<Func<bool>> expression);
/// <summary>
/// Add arbitrary ICriterion (e.g., to allow protected member access)
/// </summary>
IQueryOver<TRoot,TSubType> Where(ICriterion expression);
/// <summary>
/// Identical semantics to AndNot() to allow more readable queries
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> WhereNot(Expression<Func<TSubType, bool>> expression);
/// <summary>
/// Identical semantics to AndNot() to allow more readable queries
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> WhereNot(Expression<Func<bool>> expression);
/// <summary>
/// Identical semantics to AndRestrictionOn() to allow more readable queries
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOverRestrictionBuilder<TRoot,TSubType> WhereRestrictionOn(Expression<Func<TSubType, object>> expression);
/// <summary>
/// Identical semantics to AndRestrictionOn() to allow more readable queries
/// </summary>
/// <param name="expression">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOverRestrictionBuilder<TRoot,TSubType> WhereRestrictionOn(Expression<Func<object>> expression);
/// <summary>
/// Add projection expressed as a lambda expression
/// </summary>
/// <param name="projections">Lambda expressions</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> Select(params Expression<Func<TRoot, object>>[] projections);
/// <summary>
/// Add arbitrary IProjections to query
/// </summary>
IQueryOver<TRoot,TSubType> Select(params IProjection[] projections);
/// <summary>
/// Create a list of projections using a projection builder
/// </summary>
IQueryOver<TRoot, TSubType> Select(Func<QueryOverProjectionBuilder<TSubType>, QueryOverProjectionBuilder<TSubType>> list);
/// <summary>
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOverOrderBuilder<TRoot,TSubType> OrderBy(Expression<Func<TSubType, object>> path);
/// <summary>
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOverOrderBuilder<TRoot,TSubType> OrderBy(Expression<Func<object>> path);
/// <summary>
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOverOrderBuilder<TRoot,TSubType> ThenBy(Expression<Func<TSubType, object>> path);
/// <summary>
/// Add order expressed as a lambda expression
/// </summary>
/// <param name="path">Lambda expression</param>
/// <returns>criteria instance</returns>
IQueryOverOrderBuilder<TRoot,TSubType> ThenBy(Expression<Func<object>> path);
/// <summary>
/// Clear all orders from the query.
/// </summary>
IQueryOver<TRoot, TSubType> ClearOrders();
/// <summary>
/// Set the first result to be retrieved
/// </summary>
/// <param name="firstResult"></param>
IQueryOver<TRoot,TSubType> Skip(int firstResult);
/// <summary>
/// Set a limit upon the number of objects to be retrieved
/// </summary>
/// <param name="maxResults"></param>
IQueryOver<TRoot,TSubType> Take(int maxResults);
/// <summary>
/// Enable caching of this query result set
/// </summary>
IQueryOver<TRoot,TSubType> Cacheable();
/// <summary> Override the cache mode for this particular query. </summary>
/// <param name="cacheMode">The cache mode to use. </param>
/// <returns> this (for method chaining) </returns>
IQueryOver<TRoot,TSubType> CacheMode(CacheMode cacheMode);
/// <summary>
/// Set the name of the cache region.
/// </summary>
/// <param name="cacheRegion">the name of a query cache region, or <see langword="null" />
/// for the default query cache</param>
IQueryOver<TRoot,TSubType> CacheRegion(string cacheRegion);
/// <summary>
/// Add a subquery expression
/// </summary>
IQueryOverSubqueryBuilder<TRoot,TSubType> WithSubquery { get; }
/// <summary>
/// Specify an association fetching strategy. Currently, only
/// one-to-many and one-to-one associations are supported.
/// </summary>
/// <param name="path">A lambda expression path (e.g., ChildList[0].Granchildren[0].Pets).</param>
/// <returns></returns>
IQueryOverFetchBuilder<TRoot,TSubType> Fetch(Expression<Func<TRoot, object>> path);
/// <summary>
/// Set the lock mode of the current entity
/// </summary>
IQueryOverLockBuilder<TRoot,TSubType> Lock();
/// <summary>
/// Set the lock mode of the aliased entity
/// </summary>
IQueryOverLockBuilder<TRoot,TSubType> Lock(Expression<Func<object>> alias);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, JoinType joinType);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, JoinType joinType);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, U>> path, Expression<Func<U>> alias, JoinType joinType);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// </summary>
/// <typeparam name="U">Type of sub-criteria</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<U>> path, Expression<Func<U>> alias, JoinType joinType);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, JoinType joinType);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, JoinType joinType);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<TSubType, IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType);
/// <summary>
/// Creates a new NHibernate.IQueryOver<TRoot, U>, "rooted" at the associated entity
/// specifying a collection for the join.
/// </summary>
/// <typeparam name="U">Type of sub-criteria (type of the collection)</typeparam>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <param name="joinType">Type of join</param>
/// <returns>The created "sub criteria"</returns>
IQueryOver<TRoot,U> JoinQueryOver<U>(Expression<Func<IEnumerable<U>>> path, Expression<Func<U>> alias, JoinType joinType);
/// <summary>
/// Join an association, assigning an alias to the joined entity
/// </summary>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> JoinAlias(Expression<Func<TSubType, object>> path, Expression<Func<object>> alias);
/// <summary>
/// Join an association, assigning an alias to the joined entity
/// </summary>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> JoinAlias(Expression<Func<object>> path, Expression<Func<object>> alias);
/// <summary>
/// Join an association, assigning an alias to the joined entity
/// </summary>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <param name="joinType">Type of join</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> JoinAlias(Expression<Func<TSubType, object>> path, Expression<Func<object>> alias, JoinType joinType);
/// <summary>
/// Join an association, assigning an alias to the joined entity
/// </summary>
/// <param name="path">Lambda expression returning association path</param>
/// <param name="alias">Lambda expression returning alias reference</param>
/// <param name="joinType">Type of join</param>
/// <returns>criteria instance</returns>
IQueryOver<TRoot,TSubType> JoinAlias(Expression<Func<object>> path, Expression<Func<object>> alias, JoinType joinType);
IQueryOverJoinBuilder<TRoot,TSubType> Inner { get; }
IQueryOverJoinBuilder<TRoot,TSubType> Left { get; }
IQueryOverJoinBuilder<TRoot,TSubType> Right { get; }
IQueryOverJoinBuilder<TRoot,TSubType> Full { get; }
}
}