71 lines
3.0 KiB
C#
71 lines
3.0 KiB
C#
namespace EnvelopeGenerator.Application.Common.Interfaces.SQLExecutor;
|
|
|
|
/// <summary>
|
|
/// Provides methods for executing common queries on a given entity type.
|
|
/// This interface abstracts away the direct usage of ORM libraries (such as Entity Framework) for querying data
|
|
/// and provides asynchronous and synchronous operations for querying a collection or single entity.
|
|
/// </summary>
|
|
/// <typeparam name="TEntity">The type of the entity being queried.</typeparam>
|
|
public interface IQuery<TEntity>
|
|
{
|
|
/// <summary>
|
|
/// Asynchronously retrieves the first entity or a default value if no entity is found.
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation. The task result contains the entity or a default value.</returns>
|
|
public Task<TEntity?> FirstOrDefaultAsync();
|
|
|
|
/// <summary>
|
|
/// Asynchronously retrieves a single entity or a default value if no entity is found.
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation. The task result contains the entity or a default value.</returns>
|
|
public Task<TEntity?> SingleOrDefaultAsync();
|
|
|
|
/// <summary>
|
|
/// Asynchronously retrieves a list of entities.
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation. The task result contains the list of entities.</returns>
|
|
public Task<IEnumerable<TEntity>> ToListAsync();
|
|
|
|
/// <summary>
|
|
/// Asynchronously retrieves the first entity. Throws an exception if no entity is found.
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation. The task result contains the first entity.</returns>
|
|
public Task<TEntity> FirstAsync();
|
|
|
|
/// <summary>
|
|
/// Asynchronously retrieves a single entity. Throws an exception if no entity is found.
|
|
/// </summary>
|
|
/// <returns>A task that represents the asynchronous operation. The task result contains the single entity.</returns>
|
|
public Task<TEntity> SingleAsync();
|
|
|
|
/// <summary>
|
|
/// Synchronously retrieves the first entity or a default value if no entity is found.
|
|
/// </summary>
|
|
/// <returns>The first entity or a default value.</returns>
|
|
public TEntity? FirstOrDefault();
|
|
|
|
/// <summary>
|
|
/// Synchronously retrieves a single entity or a default value if no entity is found.
|
|
/// </summary>
|
|
/// <returns>The single entity or a default value.</returns>
|
|
public TEntity? SingleOrDefault();
|
|
|
|
/// <summary>
|
|
/// Synchronously retrieves a list of entities.
|
|
/// </summary>
|
|
/// <returns>The list of entities.</returns>
|
|
public IEnumerable<TEntity> ToList();
|
|
|
|
/// <summary>
|
|
/// Synchronously retrieves the first entity. Throws an exception if no entity is found.
|
|
/// </summary>
|
|
/// <returns>The first entity.</returns>
|
|
public TEntity First();
|
|
|
|
/// <summary>
|
|
/// Synchronously retrieves a single entity. Throws an exception if no entity is found.
|
|
/// </summary>
|
|
/// <returns>The single entity.</returns>
|
|
public TEntity Single();
|
|
}
|