Example #1
0
        /// <summary>
        /// Returns a list of distinct column values that can be used for select filters.
        /// </summary>
        /// <param name="column">The column.</param>
        public virtual IList <string> GetDistinctColumnValues(DataTablesColumn <TEntity, TEntityViewModel> column)
        {
            var parameterExp = ExpressionHelper.BuildParameterExpression <TEntity>();
            var propertyExp  = ExpressionHelper.BuildPropertyExpression(parameterExp, column.PrivatePropertyName);
            var stringExp    = Expression.Call(propertyExp, ExpressionHelper.Object_ToString);
            var lambda       = Expression.Lambda <Func <TEntity, string> >(stringExp, parameterExp);

            return(GetDistinctColumnValues(lambda));
        }
Example #2
0
        protected List <Expression <Func <TEntity, bool> > > BuildWhereExpression <TEntity>(IViewModel viewModel, IList <string> where)
        {
            //将条件按照列组合起来
            Dictionary <UiColumnInfo, List <Condition> > dictConditions = new Dictionary <UiColumnInfo, List <Condition> >();

            foreach (var filter in where)
            {
                var ss = filter.Split(' ');
                if (ss.Length != 3)
                {
                    continue;
                }
                var columnInfo = viewModel.GetColumnInfo(ss[0]);
                var condition  = new Condition()
                {
                    Key = ss[1], Value = ss[2]
                };
                if (columnInfo != null)
                {
                    if (dictConditions.ContainsKey(columnInfo))
                    {
                        List <Condition> conditions = dictConditions[columnInfo];
                        conditions.Add(condition);
                    }
                    else
                    {
                        List <Condition> conditions = new List <Condition>();
                        conditions.Add(condition);
                        dictConditions[columnInfo] = conditions;
                    }
                }
            }


            List <Expression <Func <TEntity, bool> > > expressions = new List <Expression <Func <TEntity, bool> > >();

            foreach (var columnCondition in dictConditions)
            {
                ParameterExpression parameterExpression = ExpressionHelper.BuildParameterExpression(typeof(TEntity));
                UiColumnInfo        columnInfo          = columnCondition.Key;
                Expression <Func <TEntity, bool> > prediateExpression = BuildColumnConditionExpression(parameterExpression, typeof(TEntity), columnInfo, columnCondition.Value)
                                                                        as Expression <Func <TEntity, bool> >;
                if (prediateExpression != null)
                {
                    expressions.Add(prediateExpression);
                }
            }
            return(expressions);
        }