60 lines
2.6 KiB
C#
60 lines
2.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using MongoDB.Driver;
|
|
using MongoDB.Driver.Linq;
|
|
using MongoDbGenericRepository.Models;
|
|
|
|
namespace MongoDbGenericRepository.DataAccess.Base
|
|
{
|
|
/// <summary>
|
|
/// A interface for accessing the Database and its Collections.
|
|
/// </summary>
|
|
public interface IDataAccessBase
|
|
{
|
|
/// <summary>
|
|
/// Gets a IMongoQueryable for a potentially partitioned document type and a filter.
|
|
/// </summary>
|
|
/// <typeparam name="TDocument">The document type.</typeparam>
|
|
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
|
/// <param name="filter">The filter definition.</param>
|
|
/// <param name="partitionKey">The collection partition key.</param>
|
|
/// <returns></returns>
|
|
IQueryable<TDocument> GetQuery<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
|
|
where TDocument : IDocument<TKey>
|
|
where TKey : IEquatable<TKey>;
|
|
|
|
/// <summary>
|
|
/// Gets a collections for a potentially partitioned document type.
|
|
/// </summary>
|
|
/// <typeparam name="TDocument">The document type.</typeparam>
|
|
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
|
/// <param name="document">The document.</param>
|
|
/// <returns></returns>
|
|
IMongoCollection<TDocument> HandlePartitioned<TDocument, TKey>(TDocument document)
|
|
where TDocument : IDocument<TKey>
|
|
where TKey : IEquatable<TKey>;
|
|
|
|
/// <summary>
|
|
/// Gets a collections for a potentially partitioned document type.
|
|
/// </summary>
|
|
/// <typeparam name="TDocument">The document type.</typeparam>
|
|
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
|
/// <param name="partitionKey">The collection partition key.</param>
|
|
/// <returns></returns>
|
|
IMongoCollection<TDocument> HandlePartitioned<TDocument, TKey>(string partitionKey)
|
|
where TDocument : IDocument<TKey>
|
|
where TKey : IEquatable<TKey>;
|
|
|
|
/// <summary>
|
|
/// Gets a collections for the type TDocument with a partition key.
|
|
/// </summary>
|
|
/// <typeparam name="TDocument">The document type.</typeparam>
|
|
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
|
/// <param name="partitionKey">The collection partition key.</param>
|
|
/// <returns></returns>
|
|
IMongoCollection<TDocument> GetCollection<TDocument, TKey>(string partitionKey = null)
|
|
where TDocument : IDocument<TKey>
|
|
where TKey : IEquatable<TKey>;
|
|
}
|
|
} |