コード例 #1
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);
    }
コード例 #2
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);
    }
コード例 #3
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);
    }