public static SortDefinition <T> BuildSort <T>(this ODataUriParser query, ConvertProperty propertyCalculator = null) { var orderBy = query.ParseOrderBy(); if (orderBy != null) { var sorts = new List <SortDefinition <T> >(); while (orderBy != null) { sorts.Add(OrderBy <T>(orderBy, propertyCalculator)); orderBy = orderBy.ThenBy; } if (sorts.Count > 1) { return(Builders <T> .Sort.Combine(sorts)); } else { return(sorts[0]); } } return(null); }
public static string BuildFieldDefinition(this QueryNode node, ConvertProperty convertProperty) { convertProperty = convertProperty ?? Default; var propertyParts = node.Accept(PropertyNameVisitor.Instance).ToArray(); var propertyName = convertProperty(propertyParts); return(propertyName); }
public static SortDefinition <T> OrderBy <T>(OrderByClause clause, ConvertProperty propertyCalculator = null) { var propertyName = clause.Expression.BuildFieldDefinition(propertyCalculator); if (clause.Direction == OrderByDirection.Ascending) { return(Builders <T> .Sort.Ascending(propertyName)); } else { return(Builders <T> .Sort.Descending(propertyName)); } }
public static (FilterDefinition <T> Filter, bool Last) BuildFilter <T>(this ODataUriParser query, ConvertProperty convertProperty = null, ConvertValue convertValue = null, bool supportsSearch = true) {
public static FilterDefinition <MongoContentEntity> BuildQuery(ODataUriParser query, Guid schemaId, Status[] status, ConvertProperty propertyCalculator) { var filters = new List <FilterDefinition <MongoContentEntity> > { Filter.Eq(x => x.IndexedSchemaId, schemaId), }; if (status != null) { filters.Add(Filter.Ne(x => x.IsDeleted, true)); filters.Add(Filter.In(x => x.Status, status)); } var filter = query.BuildFilter <MongoContentEntity>(propertyCalculator); if (filter.Filter != null) { if (filter.Last) { filters.Add(filter.Filter); } else { filters.Insert(0, filter.Filter); } } if (filters.Count == 1) { return(filters[0]); } else { return(Filter.And(filters)); } }
public static IFindFluent <MongoContentEntity, MongoContentEntity> ContentSort(this IFindFluent <MongoContentEntity, MongoContentEntity> cursor, ODataUriParser query, ConvertProperty propertyCalculator) { var sort = query.BuildSort <MongoContentEntity>(propertyCalculator); return(sort != null?cursor.Sort(sort) : cursor.SortByDescending(x => x.LastModified)); }
public static FilterDefinition <T> Visit(QueryNode node, ConvertProperty propertyCalculator, ConvertValue convertValue) { var visitor = new FilterVisitor <T>(propertyCalculator, convertValue); return(node.Accept(visitor)); }
private FilterVisitor(ConvertProperty convertProperty, ConvertValue convertValue) { this.convertProperty = convertProperty; this.convertValue = convertValue; }