|
|
|
@ -11,60 +11,56 @@ namespace Volo.Abp.Domain.Repositories |
|
|
|
public static class MongoDbCoreRepositoryExtensions |
|
|
|
{ |
|
|
|
[Obsolete("Use GetDatabaseAsync method.")] |
|
|
|
public static IMongoDatabase GetDatabase<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static IMongoDatabase GetDatabase<TEntity>(this IBasicRepository<TEntity> repository) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
return repository.ToMongoDbRepository().Database; |
|
|
|
} |
|
|
|
|
|
|
|
public static Task<IMongoDatabase> GetDatabaseAsync<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static Task<IMongoDatabase> GetDatabaseAsync<TEntity>(this IBasicRepository<TEntity> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
return repository.ToMongoDbRepository().GetDatabaseAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
[Obsolete("Use GetCollectionAsync method.")] |
|
|
|
public static IMongoCollection<TEntity> GetCollection<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static IMongoCollection<TEntity> GetCollection<TEntity>(this IBasicRepository<TEntity> repository) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
return repository.ToMongoDbRepository().Collection; |
|
|
|
} |
|
|
|
|
|
|
|
public static Task<IMongoCollection<TEntity>> GetCollectionAsync<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static Task<IMongoCollection<TEntity>> GetCollectionAsync<TEntity>(this IBasicRepository<TEntity> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
return repository.ToMongoDbRepository().GetCollectionAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
[Obsolete("Use GetMongoQueryableAsync method.")] |
|
|
|
public static IMongoQueryable<TEntity> GetMongoQueryable<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static IMongoQueryable<TEntity> GetMongoQueryable<TEntity>(this IBasicRepository<TEntity> repository) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
return repository.ToMongoDbRepository().GetMongoQueryable(); |
|
|
|
} |
|
|
|
|
|
|
|
public static Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static Task<IMongoQueryable<TEntity>> GetMongoQueryableAsync<TEntity>(this IBasicRepository<TEntity> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
return repository.ToMongoDbRepository().GetMongoQueryableAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
public static Task<IAggregateFluent<TEntity>> GetAggregateAsync<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static async Task<IAggregateFluent<TEntity>> GetAggregateAsync<TEntity>(this IBasicRepository<TEntity> repository, CancellationToken cancellationToken = default) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
return repository.ToMongoDbRepository().GetAggregateAsync(cancellationToken); |
|
|
|
var collection = await repository.ToMongoDbRepository().GetCollectionAsync(cancellationToken); |
|
|
|
return collection.Aggregate(); |
|
|
|
} |
|
|
|
|
|
|
|
public static IMongoDbRepository<TEntity, TKey> ToMongoDbRepository<TEntity, TKey>(this IBasicRepository<TEntity, TKey> repository) |
|
|
|
where TEntity : class, IEntity<TKey> |
|
|
|
public static IMongoDbRepository<TEntity> ToMongoDbRepository<TEntity>(this IBasicRepository<TEntity> repository) |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
var mongoDbRepository = repository as IMongoDbRepository<TEntity, TKey>; |
|
|
|
if (mongoDbRepository == null) |
|
|
|
{ |
|
|
|
throw new ArgumentException("Given repository does not implement " + typeof(IMongoDbRepository<TEntity, TKey>).AssemblyQualifiedName, nameof(repository)); |
|
|
|
} |
|
|
|
|
|
|
|
return mongoDbRepository; |
|
|
|
if (repository is IMongoDbRepository<TEntity> mongoDbRepository) return mongoDbRepository; |
|
|
|
throw new ArgumentException("Given repository does not implement " + typeof(IMongoDbRepository<TEntity>).AssemblyQualifiedName, nameof(repository)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|