You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Expressions.Query;
|
|
|
|
|
|
|
|
|
|
internal sealed class EntityQuery<TEntity> : IQueryable<TEntity>, IAsyncEnumerable<TEntity>, IOrderedQueryable<TEntity>
|
|
|
|
|
{
|
|
|
|
|
public EntityQuery(IQueryProvider provider, Expression expression)
|
|
|
|
|
{
|
|
|
|
|
Provider = provider;
|
|
|
|
|
Expression = expression;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type ElementType => typeof(TEntity);
|
|
|
|
|
|
|
|
|
|
public Expression Expression { get; }
|
|
|
|
|
|
|
|
|
|
public IQueryProvider Provider { get; }
|
|
|
|
|
|
|
|
|
|
public async IAsyncEnumerator<TEntity> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
var result = Provider.Execute(Expression);
|
|
|
|
|
|
|
|
|
|
if (result is IEnumerable en)
|
|
|
|
|
{
|
|
|
|
|
var enumerator = en.GetEnumerator();
|
|
|
|
|
|
|
|
|
|
while (enumerator.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
|
|
|
|
|
yield return (TEntity)enumerator.Current;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerator<TEntity> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return ((IEnumerable<TEntity>)Provider.Execute(Expression)).GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
return ((IEnumerable)Provider.Execute(Expression)).GetEnumerator();
|
|
|
|
|
}
|
|
|
|
|
}
|