Skip to content

IRepository<T>

Generic repository interface for data access.

Methods

MethodReturnDescription
GetByIdAsync(Guid, CancellationToken)Task<T?>Get by ID
GetAllAsync(CancellationToken)Task<IEnumerable<T>>Get all entities
FindAsync(Expression<Func<T, bool>>, CancellationToken)Task<IEnumerable<T>>Find by predicate
FirstOrDefaultAsync(Expression<Func<T, bool>>, CancellationToken)Task<T?>First match or null
AnyAsync(Expression<Func<T, bool>>, CancellationToken)Task<bool>Check if any match
AddAsync(T, CancellationToken)Task<T>Add entity
UpdateAsync(T, CancellationToken)Task<T>Update entity
DeleteAsync(Guid, CancellationToken)TaskDelete by ID
DeleteAsync(T, CancellationToken)TaskDelete entity
ExistsAsync(Guid, CancellationToken)Task<bool>Check existence
CountAsync(Expression?, CancellationToken)Task<int>Count entities

IRepository<T, TKey>

Same interface but with custom key type.

Usage

csharp
public interface IProductRepository : IRepository&lt;Product&gt;
{
    Task&lt;Product?&gt; GetBySkuAsync(string sku, CancellationToken ct);
}

Released under the MIT License.