constellation-api/CH.Dal/DefaultQueryableProvider.cs

19 lines
769 B
C#
Raw Normal View History

using OpenHarbor.CQRS.DynamicQuery.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CH.Dal;
public class DefaultQueryableProvider<TEntity>(CHDbContext dbContext, IServiceProvider serviceProvider) : IQueryableProvider<TEntity>
where TEntity : class
{
public Task<IQueryable<TEntity>> GetQueryableAsync(object query, CancellationToken cancellationToken = default)
{
if (serviceProvider.GetService(typeof(IQueryableProviderOverride<TEntity>)) is IQueryableProviderOverride<TEntity> queryableProviderOverride)
return queryableProviderOverride.GetQueryableAsync(query, cancellationToken);
return Task.FromResult(dbContext.Set<TEntity>().AsQueryable());
}
}