Files
xDataService/Mongo/XMongoQueryable.cs
2024-01-25 04:41:17 +03:30

56 lines
1.9 KiB
C#

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<TEntity, TKey> : IMongoQueryable<TEntity>
where TEntity : XBaseEntity<TKey> {
private readonly IMongoCollection<TEntity> collection;
public Type ElementType { get; }
public IQueryable<TEntity> Items { get; }
public Expression Expression { get; }
public IQueryProvider Provider { get; }
public XMongoQueryable (
IQueryable<TEntity> items,
IMongoCollection<TEntity> collection
) {
//
this.Items = items;
this.collection = collection;
//
Provider = items.Provider;
Expression = items.Expression;
ElementType = items.ElementType;
}
public IEnumerator<TEntity> GetEnumerator () {
return Items.GetEnumerator ();
}
public QueryableExecutionModel GetExecutionModel () {
return collection.AsQueryable ().GetExecutionModel ();
}
public IAsyncCursor<TEntity> ToCursor (CancellationToken cancellationToken = default) {
return new XMongoAsyncCursor<TEntity> (Items);
}
public Task<IAsyncCursor<TEntity>> ToCursorAsync (CancellationToken cancellationToken = default) {
return Task.Run (() => new XMongoAsyncCursor<TEntity> (Items) as IAsyncCursor<TEntity>);
}
IEnumerator IEnumerable.GetEnumerator () {
return Items.GetEnumerator ();
}
}
}