IRepository<T>
Generic repository interface for data access.
Methods
| Method | Return | Description |
|---|---|---|
| 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) | Task | Delete by ID |
| DeleteAsync(T, CancellationToken) | Task | Delete 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<Product>
{
Task<Product?> GetBySkuAsync(string sku, CancellationToken ct);
}