public async static Task <Paging <T> > GridifyAsync <T> (this IQueryable <T> query, IGridifyQuery gridifyQuery, IGridifyMapper <T> mapper = null)
        {
            mapper = mapper.FixMapper();
            var res = await query.GridifyQueryableAsync(gridifyQuery, mapper);

            return(new Paging <T> ()
            {
                Items = await res.Query.ToListAsync(), TotalItems = res.TotalItems
            });
        }
Beispiel #2
0
    public static Expression <Func <T, bool> > CreateQuery <T>(this SyntaxTree syntaxTree, IGridifyMapper <T>?mapper = null)
    {
        mapper = mapper.FixMapper(syntaxTree);
        var exp = ExpressionToQueryConvertor.GenerateQuery(syntaxTree.Root, mapper).Expression;

        if (exp == null)
        {
            throw new GridifyQueryException("Invalid SyntaxTree.");
        }
        return(exp);
    }
Beispiel #3
0
    public static IQueryable <T> ApplyFiltering <T>(this IQueryable <T> query, string?filter, IGridifyMapper <T>?mapper = null)
    {
        if (string.IsNullOrWhiteSpace(filter))
        {
            return(query);
        }

        var syntaxTree = SyntaxTree.Parse(filter !, GridifyGlobalConfiguration.CustomOperators.Operators);

        if (syntaxTree.Diagnostics.Any())
        {
            throw new GridifyFilteringException(syntaxTree.Diagnostics.Last());
        }

        mapper = mapper.FixMapper(syntaxTree);

        var(queryExpression, _) = ExpressionToQueryConvertor.GenerateQuery(syntaxTree.Root, mapper);

        query = query.Where(queryExpression);

        return(query);
    }
Beispiel #4
0
    public static Expression <Func <T, bool> > GetFilteringExpression <T>(this IGridifyFiltering gridifyFiltering, IGridifyMapper <T>?mapper = null)
    {
        if (string.IsNullOrWhiteSpace(gridifyFiltering.Filter))
        {
            throw new GridifyQueryException("Filter is not defined");
        }

        var syntaxTree = SyntaxTree.Parse(gridifyFiltering.Filter !, GridifyGlobalConfiguration.CustomOperators.Operators);

        if (syntaxTree.Diagnostics.Any())
        {
            throw new GridifyFilteringException(syntaxTree.Diagnostics.Last() !);
        }

        mapper = mapper.FixMapper(syntaxTree);
        var(queryExpression, _) = ExpressionToQueryConvertor.GenerateQuery(syntaxTree.Root, mapper);
        if (queryExpression == null)
        {
            throw new GridifyQueryException("Can not create expression with current data");
        }
        return(queryExpression);
    }