forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestrictions.cs
799 lines (724 loc) · 29.3 KB
/
Restrictions.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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using NHibernate.Criterion.Lambda;
using NHibernate.Impl;
namespace NHibernate.Criterion
{
/// <summary>
/// The <see cref="NHibernate.Criterion"/> namespace may be used by applications as a framework for building
/// new kinds of <see cref="ICriterion"/>.
/// However, it is intended that most applications will
/// simply use the built-in criterion types via the static factory methods of this class.
/// </summary>
/// <seealso cref="ICriteria"/>
/// <seealso cref="Projections"/>
public class Restrictions
{
internal Restrictions()
{
//cannot be instantiated
}
/// <summary>
/// Apply an "equal" constraint to the identifier property
/// </summary>
/// <param name="value"></param>
/// <returns>ICriterion</returns>
public static AbstractCriterion IdEq(object value)
{
return new IdentifierEqExpression(value);
}
/// <summary>
/// Apply an "equal" constraint from the projection to the identifier property
/// </summary>
/// <param name="projection">The projection.</param>
/// <returns>ICriterion</returns>
public static AbstractCriterion IdEq(IProjection projection)
{
return new IdentifierEqExpression(projection);
}
/// <summary>
/// Apply an "equal" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Eq(string propertyName, object value)
{
return new SimpleExpression(propertyName, value, " = ");
}
/// <summary>
/// Apply an "equal" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Eq(IProjection projection, object value)
{
return new SimpleExpression(projection, value, " = ");
}
/// <summary>
/// Apply a "like" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="value">The value for the Property.</param>
/// <returns>A <see cref="LikeExpression" />.</returns>
public static SimpleExpression Like(string propertyName, object value)
{
return new SimpleExpression(propertyName, value, " like ");
}
public static AbstractCriterion Like(string propertyName, string value, MatchMode matchMode, char? escapeChar)
{
return new LikeExpression(propertyName, value, matchMode, escapeChar, false);
}
/// <summary>
/// Apply a "like" constraint to the project
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
/// <returns>A <see cref="LikeExpression"/>.</returns>
public static SimpleExpression Like(IProjection projection, object value)
{
return new SimpleExpression(projection, value, " like ");
}
/// <summary>
/// Apply a "like" constraint to the project
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
/// <param name="matchMode">The match mode.</param>
/// <returns>A <see cref="LikeExpression"/>.</returns>
public static SimpleExpression Like(IProjection projection, string value, MatchMode matchMode)
{
return new SimpleExpression(projection, matchMode.ToMatchString(value), " like ");
}
public static SimpleExpression Like(string propertyName, string value, MatchMode matchMode)
{
return new SimpleExpression(propertyName, matchMode.ToMatchString(value), " like ");
}
public static AbstractCriterion InsensitiveLike(string propertyName, string value, MatchMode matchMode)
{
return new InsensitiveLikeExpression(propertyName, value, matchMode);
}
public static AbstractCriterion InsensitiveLike(IProjection projection, string value, MatchMode matchMode)
{
return new InsensitiveLikeExpression(projection, value, matchMode);
}
/// <summary>
/// A case-insensitive "like", similar to Postgres "ilike" operator
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="value">The value for the Property.</param>
/// <returns>An <see cref="InsensitiveLikeExpression" />.</returns>
public static AbstractCriterion InsensitiveLike(string propertyName, object value)
{
return new InsensitiveLikeExpression(propertyName, value);
}
/// <summary>
/// A case-insensitive "like", similar to Postgres "ilike" operator
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
/// <returns>
/// An <see cref="InsensitiveLikeExpression"/>.
/// </returns>
public static AbstractCriterion InsensitiveLike(IProjection projection, object value)
{
return new InsensitiveLikeExpression(projection, value);
}
/// <summary>
/// Apply a "greater than" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Gt(string propertyName, object value)
{
return new SimpleExpression(propertyName, value, " > ");
}
/// <summary>
/// Apply a "greater than" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Gt(IProjection projection, object value)
{
return new SimpleExpression(projection, value, " > ");
}
/// <summary>
/// Apply a "less than" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Lt(string propertyName, object value)
{
return new SimpleExpression(propertyName, value, " < ");
}
/// <summary>
/// Apply a "less than" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Lt(IProjection projection, object value)
{
return new SimpleExpression(projection, value, " < ");
}
/// <summary>
/// Apply a "less than or equal" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Le(string propertyName, object value)
{
return new SimpleExpression(propertyName, value, " <= ");
}
/// <summary>
/// Apply a "less than or equal" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Le(IProjection projection, object value)
{
return new SimpleExpression(projection, value, " <= ");
}
/// <summary>
/// Apply a "greater than or equal" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Ge(string propertyName, object value)
{
return new SimpleExpression(propertyName, value, " >= ");
}
/// <summary>
/// Apply a "greater than or equal" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="value">The value for the Property.</param>
public static SimpleExpression Ge(IProjection projection, object value)
{
return new SimpleExpression(projection, value, " >= ");
}
/// <summary>
/// Apply a "between" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="lo">The low value for the Property.</param>
/// <param name="hi">The high value for the Property.</param>
/// <returns>A <see cref="BetweenExpression" />.</returns>
public static AbstractCriterion Between(string propertyName, object lo, object hi)
{
return new BetweenExpression(propertyName, lo, hi);
}
/// <summary>
/// Apply a "between" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="lo">The low value for the Property.</param>
/// <param name="hi">The high value for the Property.</param>
/// <returns>A <see cref="BetweenExpression"/>.</returns>
public static AbstractCriterion Between(IProjection projection, object lo, object hi)
{
return new BetweenExpression(projection, lo, hi);
}
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="values">An array of values.</param>
/// <returns>An <see cref="InExpression" />.</returns>
public static AbstractCriterion In(string propertyName, object[] values)
{
return new InExpression(propertyName, values);
}
/// <summary>
/// Apply an "in" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="values">An array of values.</param>
/// <returns>An <see cref="InExpression"/>.</returns>
public static AbstractCriterion In(IProjection projection, object[] values)
{
return new InExpression(projection, values);
}
/// <summary>
/// Apply an "in" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="values">An ICollection of values.</param>
/// <returns>An <see cref="InExpression"/>.</returns>
public static AbstractCriterion In(IProjection projection, ICollection values)
{
object[] ary = new object[values.Count];
values.CopyTo(ary, 0);
return new InExpression(projection, ary);
}
/// <summary>
/// Apply an "in" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="values">An ICollection of values.</param>
/// <returns>An <see cref="InExpression" />.</returns>
public static AbstractCriterion In(string propertyName, ICollection values)
{
object[] ary = new object[values.Count];
values.CopyTo(ary, 0);
return new InExpression(propertyName, ary);
}
/// <summary>
/// Apply an "in" constraint to the named property. This is the generic equivalent
/// of <see cref="In(string, ICollection)" />, renamed to avoid ambiguity.
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <param name="values">An <see cref="System.Collections.Generic.IEnumerable{T}" />
/// of values.</param>
/// <returns>An <see cref="InExpression" />.</returns>
public static AbstractCriterion InG<T>(string propertyName, IEnumerable<T> values)
{
var array = new object[values.Count()];
var i = 0;
foreach (var item in values)
{
array[i] = item;
i++;
}
return new InExpression(propertyName, array);
}
/// <summary>
/// Apply an "in" constraint to the projection. This is the generic equivalent
/// of <see cref="In(string, ICollection)"/>, renamed to avoid ambiguity.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="projection">The projection.</param>
/// <param name="values">An <see cref="System.Collections.Generic.IEnumerable{T}"/>
/// of values.</param>
/// <returns>An <see cref="InExpression"/>.</returns>
public static AbstractCriterion InG<T>(IProjection projection, IEnumerable<T> values)
{
var array = new object[values.Count()];
var i = 0;
foreach (var item in values)
{
array[i] = item;
i++;
}
return new InExpression(projection, array);
}
/// <summary>
/// Apply an "is null" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <returns>A <see cref="NullExpression" />.</returns>
public static AbstractCriterion IsNull(string propertyName)
{
return new NullExpression(propertyName);
}
/// <summary>
/// Apply an "is null" constraint to the projection
/// </summary>
/// <param name="projection">The projection.</param>
/// <returns>A <see cref="NullExpression"/>.</returns>
public static AbstractCriterion IsNull(IProjection projection)
{
return new NullExpression(projection);
}
/// <summary>
/// Apply an "equal" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion EqProperty(string propertyName, string otherPropertyName)
{
return new EqPropertyExpression(propertyName, otherPropertyName);
}
/// <summary>
/// Apply an "equal" constraint to projection and property
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion EqProperty(IProjection projection, string otherPropertyName)
{
return new EqPropertyExpression(projection, otherPropertyName);
}
/// <summary>
/// Apply an "equal" constraint to lshProjection and rshProjection
/// </summary>
/// <param name="lshProjection">The LHS projection.</param>
/// <param name="rshProjection">The RSH projection.</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion EqProperty(IProjection lshProjection, IProjection rshProjection)
{
return new EqPropertyExpression(lshProjection, rshProjection);
}
/// <summary>
/// Apply an "equal" constraint to the property and rshProjection
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <param name="rshProjection">The RSH projection.</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion EqProperty(string propertyName, IProjection rshProjection)
{
return new EqPropertyExpression(propertyName, rshProjection);
}
/// <summary>
/// Apply an "not equal" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion NotEqProperty(string propertyName, string otherPropertyName)
{
return new NotExpression(new EqPropertyExpression(propertyName, otherPropertyName));
}
/// <summary>
/// Apply an "not equal" constraint to projection and property
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion NotEqProperty(IProjection projection, string otherPropertyName)
{
return new NotExpression(new EqPropertyExpression(projection, otherPropertyName));
}
/// <summary>
/// Apply an "not equal" constraint to the projections
/// </summary>
/// <param name="lhsProjection">The LHS projection.</param>
/// <param name="rhsProjection">The RHS projection.</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion NotEqProperty(IProjection lhsProjection, IProjection rhsProjection)
{
return new NotExpression(new EqPropertyExpression(lhsProjection, rhsProjection));
}
/// <summary>
/// Apply an "not equal" constraint to the projections
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <param name="rhsProjection">The RHS projection.</param>
/// <returns>A <see cref="EqPropertyExpression"/> .</returns>
public static AbstractCriterion NotEqProperty(string propertyName, IProjection rhsProjection)
{
return new NotExpression(new EqPropertyExpression(propertyName, rhsProjection));
}
/// <summary>
/// Apply a "greater than" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion GtProperty(string propertyName, string otherPropertyName)
{
return new GtPropertyExpression(propertyName, otherPropertyName);
}
/// <summary>
/// Apply a "greater than" constraint to two properties
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion GtProperty(IProjection projection, string otherPropertyName)
{
return new GtPropertyExpression(projection, otherPropertyName);
}
/// <summary>
/// Apply a "greater than" constraint to two properties
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <param name="projection">The projection.</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion GtProperty(string propertyName, IProjection projection)
{
return new GtPropertyExpression(propertyName, projection);
}
/// <summary>
/// Apply a "greater than" constraint to two properties
/// </summary>
/// <param name="lhsProjection">The LHS projection.</param>
/// <param name="rhsProjection">The RHS projection.</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion GtProperty(IProjection lhsProjection, IProjection rhsProjection)
{
return new GtPropertyExpression(lhsProjection, rhsProjection);
}
/// <summary>
/// Apply a "greater than or equal" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion GeProperty(string propertyName, string otherPropertyName)
{
return new GePropertyExpression(propertyName, otherPropertyName);
}
/// <summary>
/// Apply a "greater than or equal" constraint to two properties
/// </summary>
/// <param name="lhsProjection">The LHS projection.</param>
/// <param name="rhsProjection">The RHS projection.</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion GeProperty(IProjection lhsProjection, IProjection rhsProjection)
{
return new GePropertyExpression(lhsProjection, rhsProjection);
}
/// <summary>
/// Apply a "greater than or equal" constraint to two properties
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion GeProperty(IProjection projection, string otherPropertyName)
{
return new GePropertyExpression(projection, otherPropertyName);
}
/// <summary>
/// Apply a "greater than or equal" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="projection">The projection.</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion GeProperty(string propertyName, IProjection projection)
{
return new GePropertyExpression(propertyName, projection);
}
/// <summary>
/// Apply a "less than" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion LtProperty(string propertyName, string otherPropertyName)
{
return new LtPropertyExpression(propertyName, otherPropertyName);
}
/// <summary>
/// Apply a "less than" constraint to two properties
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion LtProperty(IProjection projection, string otherPropertyName)
{
return new LtPropertyExpression(projection, otherPropertyName);
}
/// <summary>
/// Apply a "less than" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="projection">The projection.</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion LtProperty(string propertyName, IProjection projection)
{
return new LtPropertyExpression(propertyName, projection);
}
/// <summary>
/// Apply a "less than" constraint to two properties
/// </summary>
/// <param name="lhsProjection">The LHS projection.</param>
/// <param name="rhsProjection">The RHS projection.</param>
/// <returns>A <see cref="LtPropertyExpression"/> .</returns>
public static AbstractCriterion LtProperty(IProjection lhsProjection, IProjection rhsProjection)
{
return new LtPropertyExpression(lhsProjection, rhsProjection);
}
/// <summary>
/// Apply a "less than or equal" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion LeProperty(string propertyName, string otherPropertyName)
{
return new LePropertyExpression(propertyName, otherPropertyName);
}
/// <summary>
/// Apply a "less than or equal" constraint to two properties
/// </summary>
/// <param name="projection">The projection.</param>
/// <param name="otherPropertyName">The rhs Property Name</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion LeProperty(IProjection projection, string otherPropertyName)
{
return new LePropertyExpression(projection, otherPropertyName);
}
/// <summary>
/// Apply a "less than or equal" constraint to two properties
/// </summary>
/// <param name="propertyName">The lhs Property Name</param>
/// <param name="projection">The projection.</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion LeProperty(string propertyName, IProjection projection)
{
return new LePropertyExpression(propertyName, projection);
}
/// <summary>
/// Apply a "less than or equal" constraint to two properties
/// </summary>
/// <param name="lhsProjection">The LHS projection.</param>
/// <param name="rhsProjection">The RHS projection.</param>
/// <returns>A <see cref="LePropertyExpression"/> .</returns>
public static AbstractCriterion LeProperty(IProjection lhsProjection, IProjection rhsProjection)
{
return new LePropertyExpression(lhsProjection, rhsProjection);
}
/// <summary>
/// Apply an "is not null" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <returns>A <see cref="NotNullExpression" />.</returns>
public static AbstractCriterion IsNotNull(string propertyName)
{
return new NotNullExpression(propertyName);
}
/// <summary>
/// Apply an "is not null" constraint to the named property
/// </summary>
/// <param name="projection">The projection.</param>
/// <returns>A <see cref="NotNullExpression"/>.</returns>
public static AbstractCriterion IsNotNull(IProjection projection)
{
return new NotNullExpression(projection);
}
/// <summary>
/// Apply an "is not empty" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <returns>A <see cref="IsNotEmptyExpression" />.</returns>
public static AbstractEmptinessExpression IsNotEmpty(string propertyName)
{
return new IsNotEmptyExpression(propertyName);
}
/// <summary>
/// Apply an "is empty" constraint to the named property
/// </summary>
/// <param name="propertyName">The name of the Property in the class.</param>
/// <returns>A <see cref="IsEmptyExpression" />.</returns>
public static AbstractEmptinessExpression IsEmpty(string propertyName)
{
return new IsEmptyExpression(propertyName);
}
/// <summary>
/// Return the conjunction of two expressions
/// </summary>
/// <param name="lhs">The Expression to use as the Left Hand Side.</param>
/// <param name="rhs">The Expression to use as the Right Hand Side.</param>
/// <returns>An <see cref="AndExpression" />.</returns>
public static AbstractCriterion And(ICriterion lhs, ICriterion rhs)
{
return new AndExpression(lhs, rhs);
}
/// <summary>
/// Return the disjunction of two expressions
/// </summary>
/// <param name="lhs">The Expression to use as the Left Hand Side.</param>
/// <param name="rhs">The Expression to use as the Right Hand Side.</param>
/// <returns>An <see cref="OrExpression" />.</returns>
public static AbstractCriterion Or(ICriterion lhs, ICriterion rhs)
{
return new OrExpression(lhs, rhs);
}
/// <summary>
/// Return the negation of an expression
/// </summary>
/// <param name="expression">The Expression to negate.</param>
/// <returns>A <see cref="NotExpression" />.</returns>
public static AbstractCriterion Not(ICriterion expression)
{
return new NotExpression(expression);
}
/// <summary>
/// Group expressions together in a single conjunction (A and B and C...)
/// </summary>
public static Conjunction Conjunction()
{
return new Conjunction();
}
/// <summary>
/// Group expressions together in a single disjunction (A or B or C...)
/// </summary>
public static Disjunction Disjunction()
{
return new Disjunction();
}
/// <summary>
/// Apply an "equals" constraint to each property in the key set of a IDictionary
/// </summary>
/// <param name="propertyNameValues">a dictionary from property names to values</param>
/// <returns></returns>
public static AbstractCriterion AllEq(IDictionary propertyNameValues)
{
Conjunction conj = Conjunction();
foreach (DictionaryEntry item in propertyNameValues)
{
conj.Add(Eq(item.Key.ToString(), item.Value));
}
return conj;
}
public static NaturalIdentifier NaturalId()
{
return new NaturalIdentifier();
}
/// <summary>
/// Create an ICriterion for the supplied LambdaExpression
/// </summary>
/// <typeparam name="T">generic type</typeparam>
/// <param name="expression">lambda expression</param>
/// <returns>return NHibernate.Criterion.ICriterion</returns>
public static ICriterion Where<T>(Expression<Func<T, bool>> expression)
{
ICriterion criterion = ExpressionProcessor.ProcessExpression<T>(expression);
return criterion;
}
/// <summary>
/// Create an ICriterion for the supplied LambdaExpression
/// </summary>
/// <param name="expression">lambda expression</param>
/// <returns>return NHibernate.Criterion.ICriterion</returns>
public static ICriterion Where(Expression<Func<bool>> expression)
{
ICriterion criterion = ExpressionProcessor.ProcessExpression(expression);
return criterion;
}
/// <summary>
/// Create an ICriterion for the negation of the supplied LambdaExpression
/// </summary>
/// <typeparam name="T">generic type</typeparam>
/// <param name="expression">lambda expression</param>
/// <returns>return NHibernate.Criterion.ICriterion</returns>
public static ICriterion WhereNot<T>(Expression<Func<T, bool>> expression)
{
ICriterion criterion = ExpressionProcessor.ProcessExpression<T>(expression);
return Restrictions.Not(criterion);
}
/// <summary>
/// Create an ICriterion for the negation of the supplied LambdaExpression
/// </summary>
/// <param name="expression">lambda expression</param>
/// <returns>return NHibernate.Criterion.ICriterion</returns>
public static ICriterion WhereNot(Expression<Func<bool>> expression)
{
ICriterion criterion = ExpressionProcessor.ProcessExpression(expression);
return Restrictions.Not(criterion);
}
/// <summary>
/// Build an ICriterion for the given property
/// </summary>
/// <param name="expression">lambda expression identifying property</param>
/// <returns>returns LambdaRestrictionBuilder</returns>
public static LambdaRestrictionBuilder On<T>(Expression<Func<T, object>> expression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(expression.Body);
return new LambdaRestrictionBuilder(projection);
}
/// <summary>
/// Build an ICriterion for the given property
/// </summary>
/// <param name="expression">lambda expression identifying property</param>
/// <returns>returns LambdaRestrictionBuilder</returns>
public static LambdaRestrictionBuilder On(Expression<Func<object>> expression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(expression.Body);
return new LambdaRestrictionBuilder(projection);
}
}
}