|
| 1 | + |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq.Expressions; |
| 5 | + |
| 6 | +using NHibernate.Impl; |
| 7 | +using NHibernate.SqlCommand; |
| 8 | + |
| 9 | +namespace NHibernate.Criterion.Lambda |
| 10 | +{ |
| 11 | + |
| 12 | + public class LambdaRestrictionBuilder |
| 13 | + { |
| 14 | + public class LambdaBetweenBuilder |
| 15 | + { |
| 16 | + private string propertyName; |
| 17 | + private object lo; |
| 18 | + |
| 19 | + public LambdaBetweenBuilder(string propertyName, object lo) |
| 20 | + { |
| 21 | + this.propertyName = propertyName; |
| 22 | + this.lo = lo; |
| 23 | + } |
| 24 | + |
| 25 | + public AbstractCriterion And(object hi) |
| 26 | + { |
| 27 | + return Restrictions.Between(propertyName, lo, hi); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + private string propertyName; |
| 32 | + |
| 33 | + /// <summary> |
| 34 | + /// Constructed with property name |
| 35 | + /// </summary> |
| 36 | + public LambdaRestrictionBuilder(string propertyName) |
| 37 | + { |
| 38 | + this.propertyName = propertyName; |
| 39 | + } |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// Apply a "between" constraint to the named property |
| 43 | + /// </summary> |
| 44 | + public LambdaBetweenBuilder IsBetween(object lo) |
| 45 | + { |
| 46 | + return new LambdaBetweenBuilder(propertyName, lo); |
| 47 | + } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// A case-insensitive "like", similar to Postgres "ilike" operator |
| 51 | + /// </summary> |
| 52 | + public AbstractCriterion IsInsensitiveLike(object value) |
| 53 | + { |
| 54 | + return Restrictions.InsensitiveLike(propertyName, value); |
| 55 | + } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// A case-insensitive "like", similar to Postgres "ilike" operator |
| 59 | + /// </summary> |
| 60 | + public AbstractCriterion IsInsensitiveLike(string value, MatchMode matchMode) |
| 61 | + { |
| 62 | + return Restrictions.InsensitiveLike(propertyName, value, matchMode); |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Apply an "is empty" constraint to the named property |
| 67 | + /// </summary> |
| 68 | + public AbstractEmptinessExpression IsEmpty |
| 69 | + { |
| 70 | + get { return Restrictions.IsEmpty(propertyName); } |
| 71 | + } |
| 72 | + |
| 73 | + /// <summary> |
| 74 | + /// Apply a "not is empty" constraint to the named property |
| 75 | + /// </summary> |
| 76 | + public AbstractEmptinessExpression IsNotEmpty |
| 77 | + { |
| 78 | + get { return Restrictions.IsNotEmpty(propertyName); } |
| 79 | + } |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Apply an "is null" constraint to the named property |
| 83 | + /// </summary> |
| 84 | + public AbstractCriterion IsNull |
| 85 | + { |
| 86 | + get { return Restrictions.IsNull(propertyName); } |
| 87 | + } |
| 88 | + |
| 89 | + /// <summary> |
| 90 | + /// Apply an "not is null" constraint to the named property |
| 91 | + /// </summary> |
| 92 | + public AbstractCriterion IsNotNull |
| 93 | + { |
| 94 | + get { return Restrictions.IsNotNull(propertyName); } |
| 95 | + } |
| 96 | + |
| 97 | + /// <summary> |
| 98 | + /// Apply a "like" constraint to the named property |
| 99 | + /// </summary> |
| 100 | + public SimpleExpression IsLike(object value) |
| 101 | + { |
| 102 | + return Restrictions.Like(propertyName, value); |
| 103 | + } |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// Apply a "like" constraint to the named property |
| 107 | + /// </summary> |
| 108 | + public SimpleExpression IsLike(string value, MatchMode matchMode) |
| 109 | + { |
| 110 | + return Restrictions.Like(propertyName, value, matchMode); |
| 111 | + } |
| 112 | + |
| 113 | + /// <summary> |
| 114 | + /// Apply a "like" constraint to the named property |
| 115 | + /// </summary> |
| 116 | + public AbstractCriterion IsLike(string value, MatchMode matchMode, char? escapeChar) |
| 117 | + { |
| 118 | + return Restrictions.Like(propertyName, value, matchMode, escapeChar); |
| 119 | + } |
| 120 | + |
| 121 | + } |
| 122 | + |
| 123 | +} |
0 commit comments