IDatabaseRepository<T>
Namespace: SlottyMedia.Database.Repository
This interface defines the contract for a generic database repository.
public interface IDatabaseRepository<T>
Type Parameters
T
The type of the entity that the repository will manage.
Methods
GetElementById(Guid)
Retrieves an element by its unique identifier.
Task<T> GetElementById(Guid entityId)
Parameters
entityId Guid
The unique identifier of the entity.
Returns
Task<T>
A task that represents the asynchronous operation. The task result contains the entity.
Exceptions
DatabaseMissingItemException
Thrown when the entity is not found in the database.
TableHasNoPrimaryKeyException
Thrown when the table has no primary key.
GeneralDatabaseException
Thrown when an unexpected error occurs.
GetAllElements()
Retrieves all elements from the table.
Task<List<T>> GetAllElements()
Returns
Task<List<T>>
A task that represents the asynchronous operation. The task result contains a collection of all entities.
Exceptions
GeneralDatabaseException
Thrown when an unexpected error occurs.
GetAllElements(PageRequest)
Retrieves all elements from the table. Fetches only a specified number of elements at the specified page.
Task<IPage<T>> GetAllElements(PageRequest pageRequest)
Parameters
pageRequest PageRequest
The page request
Returns
Task<IPage<T>>
A task that represents the asynchronous operation. The task result contains a collection of all entities.
Exceptions
GeneralDatabaseException
Thrown when an unexpected error occurs.
AddElement(T)
Creates a new element.
Task<T> AddElement(T element)
Parameters
element T
The entity to create.
Returns
Task<T>
A task that represents the asynchronous operation. The task result contains the created entity.
Exceptions
DatabaseIudActionException
Thrown when an error occurs while inserting the entity.
GeneralDatabaseException
Thrown when an unexpected error occurs.
UpdateElement(T)
Updates an existing element.
Task UpdateElement(T element)
Parameters
element T
The entity to update.
Returns
Task
A task that represents the asynchronous operation. The task result contains the updated entity.
Exceptions
DatabaseIudActionException
Thrown when an error occurs while updating the entity.
GeneralDatabaseException
Thrown when an unexpected error occurs.
DeleteElement(T)
Deletes an element by its object.
Task DeleteElement(T entity)
Parameters
entity T
The entity to delete.
Returns
Task
A task that represents the asynchronous operation.
Exceptions
DatabaseIudActionException
Thrown when an error occurs while deleting the entity.
GeneralDatabaseException
Thrown when an unexpected error occurs.
GetElementByField(String, String)
Retrieves an element by a specific field.
Task<T> GetElementByField(string fieldName, string fieldValue)
Parameters
fieldName String
The name of the field.
fieldValue String
The value of the field.
Returns
Task<T>
A task that represents the asynchronous operation. The task result contains the entity.
Exceptions
DatabaseMissingItemException
Thrown when the entity is not found in the database.
GeneralDatabaseException
Thrown when an unexpected error occurs.
GetElementById(Guid, Expression<Func<T, Object[]>>)
Retrieves an element by its unique identifier with a specific selector.
Task<T> GetElementById(Guid entityId, Expression<Func<T, Object[]>> selector)
Parameters
entityId Guid
The unique identifier of the entity.
selector Expression<Func<T, Object[]>>
The selector expression.
Returns
Task<T>
A task that represents the asynchronous operation. The task result contains the entity.
Exceptions
DatabaseMissingItemException
Thrown when the entity is not found in the database.
GeneralDatabaseException
Thrown when an unexpected error occurs.