示例#1
0
        /// <summary>
        /// errors are thrown on empty filed name,
        /// if value1 or value2 is null
        ///
        /// the expression will be skipped of both values are string.empty.No error thrown.
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value1"></param>
        /// <param name="value2"></param>
        /// <returns></returns>
        public IQueryBuilder AddBetween(string fieldName, string value1, string value2)
        {
            Contract.Requires <ArgumentNullException>(!string.IsNullOrWhiteSpace(fieldName));
            Contract.Requires <ArgumentNullException>(value1 != null || value2 != null);
            string betweenExpression = "{0} BETWEEN {1} AND {2}";
            var    wi = new WhereItem();

            // if there is no property name we can't really do anything.
            if (string.IsNullOrWhiteSpace(value1) && string.IsNullOrWhiteSpace(value2))
            {
                return(this);
            }

            //put the property name in there then send in the other spaces
            var expression = string.Format(betweenExpression, fieldName, "{0}", "{1}");

            wi.WhereExpression = expression;

            var prms = new List <object>()
            {
                value1, value2
            };

            wi.SqlParams.AddRange(prms);
            Where.Add(wi);
            return(this);
        }
示例#2
0
        public IQueryBuilder AddLike(string fieldName, string likeVal, bool excludeIfValIsNullOrWhiteSpace = true)
        {
            if (string.IsNullOrWhiteSpace(likeVal))
            {
                System.Diagnostics.Trace.WriteLine(string.Format("{0} was not added to the like statement because the value was null", fieldName));
                return(this);
            }
            var wi = new WhereItem()
            {
                WhereExpression = LikeExp(fieldName),
                SqlParam        = LikeSqlParam(likeVal)
            };

            Where.Add(wi);
            return(this);
        }
        /// <summary>
        /// We have three scenarios,
        /// 1. start and end are null or min, do nothnig
        /// 2. start has value, end dose not, set end to now
        /// 3. start is null or min, and end have a value, everythnig before end.
        ///
        /// If the name is null then we will not do anything.
        /// </summary>
        /// <param name="dateSearch"></param>
        /// <returns></returns>
        public WhereItem CreateQuery(DateSearch dateSearch)
        {
            var wi = new WhereItem();

            // if there is no property name we can't really do anything.
            if (string.IsNullOrWhiteSpace(dateSearch.PropertyName))
            {
                return(wi);
            }

            var fromIsMin = (dateSearch.From.CompareTo(DateTime.MinValue) == 0);
            var toIsMin   = (dateSearch.To.CompareTo(DateTime.MinValue) == 0);

            // if the values are min, then they are same as null
            if (fromIsMin && toIsMin)
            {
                return(wi);
            }


            if (!dateSearch.VerifySqlFriendly(dateSearch.From))
            {
                dateSearch.From = DateSearch.SqlMin;
            }

            if (!dateSearch.VerifySqlFriendly(dateSearch.To))
            {
                dateSearch.To = DateTime.Now;
            }
            //put the property name in there then send in the other spaces
            var expression = string.Format(BetweenExpression, dateSearch.PropertyName, "{0}", "{1}");

            wi.WhereExpression = expression;
            wi.SqlParams.AddRange(CreateParams(dateSearch));
            return(wi);
        }