Browse Source

Improve MongoDbCoreRepositoryExtensions

As same as #5697, and fix a bug.
pull/7879/head
PM Extra 5 years ago
parent
commit
055e33cb50
  1. 44
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs

44
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDbCoreRepositoryExtensions.cs

@ -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));
}
}
}

Loading…
Cancel
Save