51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
|
namespace Galaeth.Core.RepositoryInterfaces;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Generic repository with auto-generated CRUD operations.
|
||
|
/// </summary>
|
||
|
/// <typeparam name="TEntity">The entity this repository handles.</typeparam>
|
||
|
/// <typeparam name="TKeyType">The data type of the primary key.</typeparam>
|
||
|
public interface IGenericRepository<TEntity, TKeyType>
|
||
|
where TEntity : class
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Find an entity by its id.
|
||
|
/// </summary>
|
||
|
/// <param name="id">The entity's id.</param>
|
||
|
/// <returns>The entity, or null if not found.</returns>
|
||
|
Task<TEntity> FindByIdAsync(TKeyType id);
|
||
|
|
||
|
/// <summary>
|
||
|
/// Retrieve all entities.
|
||
|
/// </summary>
|
||
|
/// <returns>Collection of entities.</returns>
|
||
|
Task<IEnumerable<TEntity>> GetAllAsync();
|
||
|
|
||
|
/// <summary>
|
||
|
/// Add an entity to the table and return it's new id.
|
||
|
/// </summary>
|
||
|
/// <param name="entity">The entity to add.</param>
|
||
|
/// <returns>The id of the new entity.</returns>
|
||
|
Task<TKeyType> AddAsync(TEntity entity);
|
||
|
|
||
|
/// <summary>
|
||
|
/// Add multiple entities to the table.
|
||
|
/// </summary>
|
||
|
/// <param name="entities">The entities to add.</param>
|
||
|
/// <returns>The id of the new entity.</returns>
|
||
|
Task AddAsync(IEnumerable<TEntity> entities);
|
||
|
|
||
|
/// <summary>
|
||
|
/// Update an entity.
|
||
|
/// </summary>
|
||
|
/// <param name="entity">The entity (needs an id) to update.</param>
|
||
|
/// <returns>True if entity updated.</returns>
|
||
|
Task<bool> UpdateAsync(TEntity entity);
|
||
|
|
||
|
/// <summary>
|
||
|
/// Delete an entity by its id.
|
||
|
/// </summary>
|
||
|
/// <param name="id">The entity id.</param>
|
||
|
Task DeleteAsync(TKeyType id);
|
||
|
}
|