示例#1
0
        public void Regex()
        {
            var map = MappingRepo <SimpleObject> .GetMap();

            var property = ExpressionProcessor <SimpleObject> .GetPropertyFromCache(x => x.Long);

            var res        = new RegexRestriction <string>(property, "[a-zA-Z]+");
            var parameters = new List <object>();
            var sql        = res.Apply(parameters, map.Dialect);

            Assert.AreEqual("`LongColumnName` REGEXP ?p0", sql);
            Assert.AreEqual("[a-zA-Z]+", parameters[0]);
        }
        public void Equal()
        {
            var map = MappingRepo <SimpleObject> .GetMap();

            var property = ExpressionProcessor <SimpleObject> .GetPropertyFromCache(x => x.Long);

            var res        = new OperatorRestriction <long>(property, 5L, "=");
            var parameters = new List <object>();
            var sql        = res.Apply(parameters, map.Dialect);

            Assert.AreEqual("`LongColumnName` = ?p0", sql);
            Assert.AreEqual(5, parameters[0]);
        }
        public void In()
        {
            var map = MappingRepo <SimpleObject> .GetMap();

            var property = ExpressionProcessor <SimpleObject> .GetPropertyFromCache(x => x.Long);

            var values     = new[] { 1L, 2, 3 };
            var res        = new InRestriction <long>(property, values);
            var parameters = new List <object>();
            var sql        = res.Apply(parameters, map.Dialect);

            Assert.AreEqual("`LongColumnName` IN (?p0,?p1,?p2)", sql);
            CollectionAssert.AreEquivalent(values, parameters);
        }
        public IQueryBuilder <T> OrderBy(Expression <Func <T, object> > expression, bool ascending)
        {
            if (_orderBy == null)
            {
                _orderBy = new List <KeyValuePair <Property, bool> >();
            }

            _orderBy.Add(new KeyValuePair <Property, bool>(
                             ExpressionProcessor <T> .GetPropertyFromCache(expression),
                             ascending
                             ));

            return(this);
        }
        public string GetSql(Action <IRestrictable <T> > restriction, Expression <Func <T, object> > accessor, int amount, List <object> parameters)
        {
            var restrictable = new Restrictable <T>();

            restriction(restrictable);
            var where = restrictable.BuildRestrictionsIncludeWhere(parameters, _map.Dialect);

            var property = ExpressionProcessor <T> .GetPropertyFromCache(accessor);

            if (property.Update)
            {
                throw new MoranbernateMappingException("Can't use property " + property.Name + " for atomic increment as it is not defined as Readonly");
            }

            return(string.Format("UPDATE {0} SET {1} = {1} + {2}{3};", _map.TableName, property.Name, amount, where));
        }
示例#6
0
 public static IRestrictable <T> IsNotNull <T, TValue>(this IRestrictable <T> restrictable, Expression <Func <T, TValue> > member)
 {
     return(restrictable.AddRestriction(new IsNullRestriction(ExpressionProcessor <T> .GetPropertyFromCache(member), not: true)));
 }
示例#7
0
 public static IRestrictable <T> LessThan <T, TValue>(this IRestrictable <T> restrictable, Expression <Func <T, TValue> > member, TValue value)
 {
     return(restrictable.AddRestriction(new OperatorRestriction <TValue>(ExpressionProcessor <T> .GetPropertyFromCache(member), value, "<")));
 }
示例#8
0
 public static IRestrictable <T> NotIn <T, TValue>(this IRestrictable <T> restrictable, Expression <Func <T, TValue> > member, ICollection <TValue> value)
 {
     return(restrictable.AddRestriction(new InRestriction <TValue>(ExpressionProcessor <T> .GetPropertyFromCache(member), value, not: true)));
 }
示例#9
0
 private static IRestrictable <T> LikeActions <T>(IRestrictable <T> restrictable, Expression <Func <T, object> > member, string value)
 {
     return(restrictable.AddRestriction(new OperatorRestriction <string>(ExpressionProcessor <T> .GetPropertyFromCache(member), value, "LIKE")));
 }
示例#10
0
 public static IRestrictable <T> RegexMatch <T>(this IRestrictable <T> restrictable, Expression <Func <T, object> > member, string pattern)
 {
     return(restrictable.AddRestriction(new RegexRestriction <string>(ExpressionProcessor <T> .GetPropertyFromCache(member), pattern)));
 }
示例#11
0
 public static IRestrictable <T> NotLike <T>(this IRestrictable <T> restrictable, Expression <Func <T, object> > member, string value)
 {
     return(restrictable.AddRestriction(new OperatorRestriction <string>(ExpressionProcessor <T> .GetPropertyFromCache(member), "%" + value + "%", "NOT LIKE")));
 }