Esempio n. 1
0
        /// <summary>
        /// Creates a primary key filter based on an entity.
        /// </summary>
        /// <param name="entity">The entity to read from.</param>
        /// <returns></returns>
        public ClassFilter CreatePrimaryKeyFilter(object entity)
        {
            if (_PrimaryKeys.Count == 0)
            {
                return(null);
            }
            else
            {
                ClassFilterTerm first = new ClassFilterTerm(
                    this,
                    _PrimaryKeys.First.Value,
                    base[_PrimaryKeys.First.Value].GetValue(entity));

                if (_PrimaryKeys.Count == 1)
                {
                    return(first);
                }
                else
                {
                    ClassFilterExpression exp = new ClassFilterExpression(first);
                    for (LinkedListNode <int> node = _PrimaryKeys.First.Next; node != null; node = node.Next)
                    {
                        exp.And(node.Value, base[node.Value].GetValue(entity));
                    }
                    return(exp);
                }
            }
        }
Esempio n. 2
0
        public ClassFilter CreateSearchFilter(DataAspect aspect, string filter)
        {
            if (string.IsNullOrEmpty(filter))
            {
                return(null);
            }
            else if (filter.Length < 3)
            {
                filter = filter + "%";
            }
            else
            {
                filter = "%" + filter.Replace(' ', '%') + "%";
            }

            Type stringType = typeof(string);
            ClassFilterExpression expression = null;
            DataAspect            dataAspect = aspect;
            int count = dataAspect.Count;

            for (int i = 0; i < count; i++)
            {
                //if (dataAspect[i].DataType == stringType)
                expression =
                    expression == null ?
                    new ClassFilterExpression(dataAspect, i, FilterComparison.Like, filter) :
                    expression.Or(i, FilterComparison.Like, filter);
            }

            return(expression);
        }
Esempio n. 3
0
 public ClassSelect <T> Search(string filter, params string[] fields)
 {
     if (string.IsNullOrEmpty(filter))
     {
         return(this);
     }
     else
     {
         ClassFilterExpression expression = new ClassFilterExpression(this._Aspect, fields[0], FilterComparison.Like, filter);
         for (int i = 1; i < fields.Length; i++)
         {
             expression.Or(fields[i], FilterComparison.Like, filter);
         }
         if (this._WhereFirst == null)
         {
             return(Where(expression));
         }
         else
         {
             return(And(expression));
         }
     }
 }
Esempio n. 4
0
 public virtual void AppendFilterExpression(StringBuilder builder, DataAspect aspect, ClassFilterExpression expression)
 {
     builder.Append("(");
     AppendFilterNodes(builder, aspect, expression.First);
     builder.Append(")");
 }