// TODO: Create unit-test-friendly wrappers for all async Linq extension methods

        public static async Task <int> CountAsyncOk <T>(
            this IQueryable <T> query,
            CancellationToken cancellationToken = default)
        =>
        query.Provider.GetType() == typeof(NHibernate.Linq.DefaultQueryProvider) ?
        await LinqExtensionMethods.CountAsync(query, cancellationToken)
            :
        query.Count();