Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
axelheer committed Mar 27, 2020
1 parent 3b18404 commit 5e0497a
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions src/NeinLinq.EntityFrameworkCore/RewriteEntityQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,11 @@ public override IQueryable CreateQuery(Expression expression)
public virtual TResult ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken = default)
{
// execute query with rewritten expression; async, if possible
if (Provider is IAsyncQueryProvider asyncProvider)
return asyncProvider.ExecuteAsync<TResult>(Rewrite(expression), cancellationToken);
if (typeof(TResult).IsGenericType)
{
// TODO: there is a better solution for that, right?
var resultDefinition = typeof(TResult).GetGenericTypeDefinition();
if (resultDefinition == typeof(Task<>))
return Execute<TResult>(ExecuteTaskMethod, expression);
if (resultDefinition == typeof(IAsyncEnumerable<>))
return Execute<TResult>(ExecuteAsyncEnumerableMethod, expression);
}
return Provider.Execute<TResult>(Rewrite(expression));
return Provider is IAsyncQueryProvider asyncProvider
? asyncProvider.ExecuteAsync<TResult>(Rewrite(expression), cancellationToken)
: typeof(Task).IsAssignableFrom(typeof(TResult))
? Execute<TResult>(ExecuteTaskMethod, expression)
: Provider.Execute<TResult>(Rewrite(expression));
}

private TResult Execute<TResult>(MethodInfo method, Expression expression)
Expand All @@ -73,11 +66,5 @@ private static readonly MethodInfo ExecuteTaskMethod

private Task<TResult> ExecuteTask<TResult>(Expression expression)
=> Task.FromResult(Provider.Execute<TResult>(Rewrite(expression)));

private static readonly MethodInfo ExecuteAsyncEnumerableMethod
= typeof(RewriteEntityQueryProvider).GetMethod(nameof(ExecuteAsyncEnumerable), BindingFlags.Instance | BindingFlags.NonPublic)!;

private IAsyncEnumerable<TResult> ExecuteAsyncEnumerable<TResult>(Expression expression)
=> new RewriteQueryEnumerable<TResult>(Provider.Execute<IEnumerable<TResult>>(Rewrite(expression)));
}
}

0 comments on commit 5e0497a

Please sign in to comment.