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.
Connected.Framework/Connected.Expressions/Query/QueryProvider.cs

49 lines
1.3 KiB

2 years ago
using Connected.Entities.Query;
using System.Linq.Expressions;
namespace Connected.Expressions.Query;
public abstract class QueryProvider : IAsyncQueryProvider
{
public IQueryable CreateQuery(Expression expression)
{
var type = expression.Type.GetElementType();
var generic = typeof(EntityQuery<>).MakeGenericType(new Type[] { type });
if (generic is null)
throw new NullReferenceException(nameof(type));
var instance = Activator.CreateInstance(generic, new object[] { this, expression }) as IQueryable;
if (instance is null)
throw new NullReferenceException(nameof(type));
return instance;
}
public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
{
return new EntityQuery<TElement>(this, expression);
}
public object? Execute(Expression expression)
{
return OnExecute(expression);
}
public object? Execute(Expression expression, CancellationToken cancellationToken = default)
{
return OnExecute(expression);
}
public TResult Execute<TResult>(Expression expression)
{
return (TResult)OnExecute(expression);
}
protected virtual object? OnExecute(Expression expression)
{
return default;
}
}