public static dynamic GetAutoQuery <TEntity>(string queryString, Type entityType, IQueryable <TEntity> query, AutoQueryableProfile profile) where TEntity : class { // If query string empty select default entity properties. if (string.IsNullOrEmpty(queryString)) { IColumnProvider columnProvider = ProviderFactory.GetColumnProvider(); IEnumerable <SelectColumn> selectColumns = EntityColumnHelper.GetSelectableColumns(profile, entityType); if (profile.UseBaseType) { return(query.Select(SelectHelper.GetSelector <TEntity, TEntity>(selectColumns, profile))); } return(query.Select(SelectHelper.GetSelector <TEntity, object>(selectColumns, profile))); } // Get criteria & clauses from choosen provider (AQ, OData, ...) string[] queryStringParts = queryString.GetParts(); ICriteriaProvider criteriaProvider = ProviderFactory.GetCriteriaProvider(profile?.ProviderType); IList <Criteria> criterias = profile.IsClauseAllowed(ClauseType.Filter) ? criteriaProvider.GetCriterias(entityType, queryStringParts, profile).ToList() : null; IClauseProvider clauseProvider = ProviderFactory.GetClauseProvider(profile?.ProviderType); Clauses clauses = clauseProvider.GetClauses(queryStringParts, profile); var countAllRows = false; IEnumerable <WrapperPartType> wrapperParts = null; if (clauses.WrapWith != null) { IWrapperProvider wrapperProvider = ProviderFactory.GetWrapperProvider(); wrapperParts = wrapperProvider.GetWrapperParts(clauses.WrapWith.Value.Split(','), profile).ToList(); countAllRows = wrapperParts.Contains(WrapperPartType.TotalCount); } QueryResult queryResult = QueryBuilder.Build(query, entityType, clauses, criterias, profile, countAllRows); if (clauses.WrapWith == null || !wrapperParts.Any()) { return(queryResult.Result); } return(DefaultWrapperProvider.GetWrappedResult(wrapperParts, queryResult, clauses, queryString)); }
public Clauses GetClauses(string[] queryStringParts, AutoQueryableProfile profile) { var clauses = new Clauses(); foreach (string q in queryStringParts) { if (q.Contains(ClauseAlias.Select, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Select)) { clauses.Select = GetClause(q, ClauseAlias.Select, ClauseType.Select); } else if (q.Contains(ClauseAlias.Top, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Top)) { clauses.Top = GetClause(q, ClauseAlias.Top, ClauseType.Top); } else if (q.Contains(ClauseAlias.Take, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Top)) { clauses.Top = GetClause(q, ClauseAlias.Take, ClauseType.Top); } else if (q.Contains(ClauseAlias.Skip, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Skip)) { clauses.Skip = GetClause(q, ClauseAlias.Skip, ClauseType.Skip); } else if (q.Contains(ClauseAlias.First, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.First)) { clauses.First = new Clause { ClauseType = ClauseType.First }; } else if (q.Contains(ClauseAlias.Last, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Last)) { clauses.Last = new Clause { ClauseType = ClauseType.Last }; } else if (q.Contains(ClauseAlias.OrderBy, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.OrderBy)) { clauses.OrderBy = GetClause(q, ClauseAlias.OrderBy, ClauseType.OrderBy); } else if (q.Contains(ClauseAlias.OrderByDesc, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.OrderByDesc)) { clauses.OrderByDesc = GetClause(q, ClauseAlias.OrderByDesc, ClauseType.OrderByDesc); } else if (q.Contains(ClauseAlias.WrapWith, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.WrapWith)) { clauses.WrapWith = GetClause(q, ClauseAlias.WrapWith, ClauseType.WrapWith); } } return(clauses); }
public Clauses GetClauses(string[] queryStringParts, AutoQueryableProfile profile) { var clauses = new Clauses(); foreach (string q in queryStringParts) { if (q.Contains(ClauseAlias.Select, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Select)) { clauses.Select = GetClause(q, ClauseAlias.Select, ClauseType.Select); } else if (q.Contains(ClauseAlias.Top, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Top)) { clauses.Top = GetClause(q, ClauseAlias.Top, ClauseType.Top); } else if (q.Contains(ClauseAlias.Skip, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Skip)) { clauses.Skip = GetClause(q, ClauseAlias.Skip, ClauseType.Skip); } else if (q.Contains(ClauseAlias.OrderBy, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.OrderBy)) { clauses.OrderBy = GetClause(q, ClauseAlias.OrderBy, ClauseType.OrderBy); } else if (q.Contains(ClauseAlias.Filter, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Filter)) { clauses.Filter = GetClause(q, ClauseAlias.Filter, ClauseType.Filter); } else if (q.Contains(ClauseAlias.Expand, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Expand)) { clauses.Expand = GetClause(q, ClauseAlias.Expand, ClauseType.Expand); } else if (q.Contains(ClauseAlias.Search, StringComparison.OrdinalIgnoreCase) && profile.IsClauseAllowed(ClauseType.Search)) { clauses.Search = GetClause(q, ClauseAlias.Search, ClauseType.Search); } } return(clauses); }