예제 #1
0
        private static IQueryable <TModel> ListAddSearchQuery <TModel>(IQueryable <TModel> query, Func <string, string> getDomainFieldFor, GridSettings gridQuery)
        {
            if (gridQuery.Where != null)
            {
                if (gridQuery.Where.GroupOp == "AND")
                {
                    foreach (var rule in gridQuery.Where.Rules)
                    {
                        query = query.Where(getDomainFieldFor(rule.Field), rule.Data, rule.Op);
                    }
                }
                else if (gridQuery.Where.GroupOp == "OR")
                {
                    var temp = (new List <TModel>()).AsQueryable();

                    foreach (var rule in gridQuery.Where.Rules)
                    {
                        var t = query.Where(getDomainFieldFor(rule.Field), rule.Data, rule.Op);
                        temp = temp.Concat(t);
                    }

                    //remove repeat records
                    query = temp.Distinct();
                }
            }

            return(query);
        }