public static IFindFluent <TDocument, BsonDocument> Only <TDocument>(this IFindFluent <TDocument, TDocument> find, Expression <Func <TDocument, object> > include1, Expression <Func <TDocument, object> > include2) { return(find.Project <BsonDocument>(Builders <TDocument> .Projection.Include(include1).Include(include2))); }
public static IFindFluent <MongoAssetEntity, MongoAssetEntity> AssetSort(this IFindFluent <MongoAssetEntity, MongoAssetEntity> cursor, ClrQuery query) { return(cursor.Sort(query.BuildSort <MongoAssetEntity>())); }
/// <summary> /// Sorts the results by a descending field. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam> /// <param name="find">The fluent find.</param> /// <param name="field">The field.</param> /// <returns>The fluent find interface.</returns> public static IOrderedFindFluent <TDocument, TProjection> SortByDescending <TDocument, TProjection>(this IFindFluent <TDocument, TProjection> find, Expression <Func <TDocument, object> > field) { Ensure.IsNotNull(find, nameof(find)); Ensure.IsNotNull(field, nameof(field)); // We require an implementation of IFindFluent<TDocument, TProjection> // to also implement IOrderedFindFluent<TDocument, TProjection> return((IOrderedFindFluent <TDocument, TProjection>)find.Sort( new DirectionalSortDefinition <TDocument>(new ExpressionFieldDefinition <TDocument>(field), SortDirection.Descending))); }
public static IFindFluent <TDocument, TDocument> Page <TDocument>(this IFindFluent <TDocument, TDocument> find, QueryBase query) { return(find.Skip(query.Skip).Limit(query.Take)); }
/// <summary> /// Get the first result or null. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam> /// <param name="find">The fluent find.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A Task whose result is the first result or null.</returns> public static Task <TProjection> FirstOrDefaultAsync <TDocument, TProjection>(this IFindFluent <TDocument, TProjection> find, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(find, nameof(find)); return(AsyncCursorHelper.FirstOrDefaultAsync(find.Limit(1).ToCursorAsync(cancellationToken), cancellationToken)); }
/// <summary> /// Projects the result. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam> /// <param name="find">The fluent find.</param> /// <param name="projection">The projection.</param> /// <returns>The fluent find interface.</returns> public static IFindFluent <TDocument, BsonDocument> Project <TDocument, TProjection>(this IFindFluent <TDocument, TProjection> find, ProjectionDefinition <TDocument, BsonDocument> projection) { Ensure.IsNotNull(find, nameof(find)); Ensure.IsNotNull(projection, nameof(projection)); return(find.Project <BsonDocument>(projection)); }
T IQuery <T> .First() { IFindFluent <T, T> finder = BuildQueryable(); return(finder.FirstOrDefault()); }
public static IFindFluent <TDocument, TNewProjection> Project <TDocument, TNewProjection>(this IFindFluent <TDocument, TDocument> findFluent) where TNewProjection : class, new() { return(findFluent.Project(ExpressionMapper.MapExp <TDocument, TNewProjection>())); }
public List <R> ToListAs <R>(Expression <Func <T, R> > singleSelector) { IFindFluent <T, T> finder = BuildQueryable(); return(finder.ToList().Select(singleSelector.Compile()).ToList()); }
public List <R> ToListAs <R>() where R : class, new() { IFindFluent <T, T> finder = BuildQueryable(); return(finder.As <R>().ToList()); }
public R FirstAs <R>() where R : class, new() { IFindFluent <T, T> finder = BuildQueryable(); return(finder.As <R>().FirstOrDefault()); }
List <T> IQuery <T> .ToList() { IFindFluent <T, T> finder = BuildQueryable(); return(finder.ToList()); }
public static IFindFluent <MongoContentEntity, MongoContentEntity> Sort(this IFindFluent <MongoContentEntity, MongoContentEntity> cursor, ODataUriParser query, Schema schema) { return(cursor.Sort(SortBuilder.BuildSort(query, schema))); }
protected void DisplayQuery <TIn, TOut>(IFindFluent <TIn, TOut> query) { output.WriteLine(query.ToString()); output.WriteLine("============================"); }
public static IFindFluent <MongoAssetEntity, MongoAssetEntity> AssetSkip(this IFindFluent <MongoAssetEntity, MongoAssetEntity> cursor, ODataUriParser query) { return(cursor.Skip(query)); }
public static IFindFluent <T, T> Page <T>(this IFindFluent <T, T> findFluent, int pageIndex, int pageSize) { pageSize = Math.Min(30, pageSize); return(findFluent.Skip((pageIndex - 1) * pageSize).Limit(pageSize)); }
public FindFluentPagingContainer(IFindFluent <TEntity, TEntity> source) { _source = source; }
/// <inheritdoc /> protected override IFindFluent <Language, Language> Sort(IFindFluent <Language, Language> find) { return(find.SortBy(lang => lang.Identifier)); }
public static FindFluentPagingContainer <TEntity> New( IFindFluent <TEntity, TEntity> find) => new FindFluentPagingContainer <TEntity>(find);
/// <summary> /// Gets a single result or null. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam> /// <param name="find">The fluent find.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A Task whose result is the single result or null.</returns> public static Task <TProjection> SingleOrDefaultAsync <TDocument, TProjection>(this IFindFluent <TDocument, TProjection> find, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(find, nameof(find)); if (!find.Options.Limit.HasValue || find.Options.Limit.Value > 2) { find = find.Limit(2); } return(AsyncCursorHelper.SingleOrDefaultAsync(find.ToCursorAsync(cancellationToken), cancellationToken)); }
public static IFindFluent <MongoContentEntity, MongoContentEntity> ContentSort(this IFindFluent <MongoContentEntity, MongoContentEntity> cursor, ODataUriParser query, PropertyCalculator propertyCalculator) { var sort = query.BuildSort <MongoContentEntity>(propertyCalculator); return(sort != null?cursor.Sort(sort) : cursor.SortByDescending(x => x.LastModified)); }
/// <summary> /// Projects the result. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam> /// <typeparam name="TNewProjection">The type of the new projection.</typeparam> /// <param name="find">The fluent find.</param> /// <param name="projection">The projection.</param> /// <returns>The fluent find interface.</returns> public static IFindFluent <TDocument, TNewProjection> Project <TDocument, TProjection, TNewProjection>(this IFindFluent <TDocument, TProjection> find, Expression <Func <TDocument, TNewProjection> > projection) { Ensure.IsNotNull(find, nameof(find)); Ensure.IsNotNull(projection, nameof(projection)); return(find.Project <TNewProjection>(new FindExpressionProjectionDefinition <TDocument, TNewProjection>(projection))); }
public static IFindFluent <MongoContentEntity, MongoContentEntity> ContentTake(this IFindFluent <MongoContentEntity, MongoContentEntity> cursor, ODataUriParser query) { return(cursor.Take(query, 200, 20)); }
public async static Task <PaginatedMongoList <TModel, RModel> > ToPaginatedMongoListAsync <TModel, RModel>(this IFindFluent <TModel, TModel> source, IComponentContext container, AInBox.Astove.Core.Options.Filter filter, SortOptions sortOptions, KeyValue parentId, int pageIndex, int pageSize) where TModel : class, IMongoModel, new() where RModel : class, IMongoModel, IDto, new() { FilterOptions options = null; FilterCondition[] conditions = null; if (filter != null && (filter.Options != null || filter.Conditions != null)) { options = new FilterOptions { Filters = filter.Options.Filters.Where(f => f.Internal == false).ToList() }; conditions = filter.Conditions.Where(c => c.Internal == false).ToArray(); } int totalCount = (int)await source.CountAsync(); int totalPageCount = (int)Math.Ceiling(totalCount / (double)pageSize); if ((pageIndex - 1) > totalPageCount) { pageIndex = totalPageCount; } var paginatedData = await source.Skip((pageIndex - 1) *pageSize).Limit(pageSize).ToListAsync(); var returnData = new List <RModel>(); paginatedData.ForEach(p => returnData.Add(p.CreateInstanceOf <RModel>())); return(new PaginatedMongoList <TModel, RModel>(container, options, conditions, sortOptions, parentId, pageIndex, pageSize, totalCount, returnData, source)); }
public static IFindFluent <MongoContentEntity, MongoContentEntity> ContentSort(this IFindFluent <MongoContentEntity, MongoContentEntity> cursor, Query query) { return(cursor.Sort(query.BuildSort <MongoContentEntity>())); }
public static Task <List <TDocument> > ToListAsync <TDocument>(this IFindFluent <TDocument, TDocument> find, QueryBase query, CancellationToken ct) { return(find.Skip(query.Skip).Limit(query.Take).ToListAsync(ct)); }
public static IFindFluent <MongoContentEntity, MongoContentEntity> ContentSkip(this IFindFluent <MongoContentEntity, MongoContentEntity> cursor, Query query) { return(cursor.Skip(query)); }
public static IFindFluent <TDocument, TDocument> Not <TDocument>(this IFindFluent <TDocument, TDocument> find, Expression <Func <TDocument, object> > exclude1, Expression <Func <TDocument, object> > exclude2) { return(find.Project <TDocument>(Builders <TDocument> .Projection.Exclude(exclude1).Exclude(exclude2))); }
private async Task <IEnumerable <T> > Find <T>(ObjectSerializer Serializer, IMongoCollection <BsonDocument> Collection, int Offset, int MaxCount, FilterDefinition <BsonDocument> BsonFilter, params string[] SortOrder) { IFindFluent <BsonDocument, BsonDocument> ResultSet = Collection.Find <BsonDocument>(BsonFilter); if (SortOrder.Length > 0) { SortDefinition <BsonDocument> SortDefinition = null; foreach (string SortBy in SortOrder) { if (SortDefinition is null) { if (SortBy.StartsWith("-")) { SortDefinition = Builders <BsonDocument> .Sort.Descending(Serializer.ToShortName(SortBy.Substring(1))); } else { SortDefinition = Builders <BsonDocument> .Sort.Ascending(Serializer.ToShortName(SortBy)); } } else { if (SortBy.StartsWith("-")) { SortDefinition = SortDefinition.Descending(Serializer.ToShortName(SortBy.Substring(1))); } else { SortDefinition = SortDefinition.Ascending(Serializer.ToShortName(SortBy)); } } } ResultSet = ResultSet.Sort(SortDefinition); } if (Offset > 0) { ResultSet = ResultSet.Skip(Offset); } if (MaxCount < int.MaxValue) { ResultSet = ResultSet.Limit(MaxCount); } IAsyncCursor <BsonDocument> Cursor = await ResultSet.ToCursorAsync(); LinkedList <T> Result = new LinkedList <T>(); BsonDeserializationArgs Args = new BsonDeserializationArgs() { NominalType = typeof(T) }; while (await Cursor.MoveNextAsync()) { foreach (BsonDocument Document in Cursor.Current) { BsonDocumentReader Reader = new BsonDocumentReader(Document); BsonDeserializationContext Context = BsonDeserializationContext.CreateRoot(Reader); T Obj = (T)Serializer.Deserialize(Context, Args); Result.AddLast(Obj); } } return(Result); }
}// private Task<IDisposable> ToListAsync(IFindFluent<BsonDocument, BsonDocument> findFluent) { throw new NotImplementedException(); }
/// <summary> /// 获取一条数据 /// </summary> /// <param name="collName">表名</param> /// <param name="filter">条件</param> /// <returns></returns> public BsonDocument Get(String collName, FilterDefinition <BsonDocument> filter) { IFindFluent <BsonDocument, BsonDocument> find = Database.GetCollection <BsonDocument>(collName).Find(filter); return(find.FirstOrDefault()); }