using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; using xModels.Base; namespace xDataService.Mongo { public class XMongoQueryable : IMongoQueryable where TEntity : XBaseEntity { private readonly IMongoCollection collection; public Type ElementType { get; } public IQueryable Items { get; } public Expression Expression { get; } public IQueryProvider Provider { get; } public XMongoQueryable ( IQueryable items, IMongoCollection collection ) { // this.Items = items; this.collection = collection; // Provider = items.Provider; Expression = items.Expression; ElementType = items.ElementType; } public IEnumerator GetEnumerator () { return Items.GetEnumerator (); } public QueryableExecutionModel GetExecutionModel () { return collection.AsQueryable ().GetExecutionModel (); } public IAsyncCursor ToCursor (CancellationToken cancellationToken = default) { return new XMongoAsyncCursor (Items); } public Task> ToCursorAsync (CancellationToken cancellationToken = default) { return Task.Run (() => new XMongoAsyncCursor (Items) as IAsyncCursor); } IEnumerator IEnumerable.GetEnumerator () { return Items.GetEnumerator (); } } }