using Microsoft.EntityFrameworkCore; using System.Linq.Expressions; namespace Core.Blueprint.DAL.SQLServer { /// /// Defines the contract for a generic repository to manage entities in a SQL Server database. /// /// The type of the entity managed by the repository. Must be a class. /// The type of the database context used by the repository. Must inherit from . public interface IEntityRepository where TEntity : class where TContext : DbContext { /// /// Retrieves all entities of type from the database. /// /// A task representing the asynchronous operation, with a collection of entities as the result. Task> GetAllAsync(); /// /// Retrieves all entities of type from the database that match a specified condition. /// /// An expression to filter the entities. /// A task representing the asynchronous operation, with a collection of matching entities as the result. Task> GetByConditionAsync(Expression> predicate); /// /// Retrieves a single entity of type by its identifier. /// /// The identifier of the entity to retrieve. /// A task representing the asynchronous operation, with the entity as the result, or null if not found. Task GetByIdAsync(int id); /// /// Retrieves the first entity of type that matches a specified condition, or null if no match is found. /// /// An expression to filter the entities. /// A task representing the asynchronous operation, with the matching entity as the result, or null if none match. Task FirstOrDefaultAsync(Expression> predicate); /// /// Adds a new entity of type to the database. /// /// The entity to add. /// A task representing the asynchronous operation. Task AddAsync(TEntity entity); /// /// Adds multiple entities of type to the database. /// /// The collection of entities to add. /// A task representing the asynchronous operation. Task AddRangeAsync(IEnumerable entities); /// /// Updates an existing entity of type in the database. /// /// The entity to update. /// The updated entity. TEntity Update(TEntity entity); /// /// Updates multiple entities of type in the database. /// /// The collection of entities to update. void UpdateRange(IEnumerable entities); /// /// Deletes an entity of type from the database. /// /// The entity to delete. void Delete(TEntity entity); /// /// Deletes multiple entities of type from the database. /// /// The collection of entities to delete. void DeleteRange(IEnumerable entities); /// /// Determines whether any entities of type exist in the database that match a specified condition. /// /// An expression to filter the entities. /// A task representing the asynchronous operation, with a boolean result indicating whether any match exists. Task AnyAsync(Expression> predicate); /// /// Executes a raw SQL query and maps the result to entities of type . /// /// The raw SQL query to execute. /// Optional parameters for the SQL query. /// A task representing the asynchronous operation, with a collection of entities as the result. Task> ExecuteRawSqlAsync(string sql, params object[] parameters); /// /// Counts the total number of entities of type in the database. /// /// A task representing the asynchronous operation, with the count as the result. Task CountAsync(); /// /// Saves all pending changes to the database. /// /// A task representing the asynchronous operation. Task SaveAsync(); } }