Skip to main content

Class ScriptableRepository<T>

A concrete implementation of IRepository that uses an IDatabaseContext to persist and retrieve entities. Assumes that entities implement IPrimaryKey with an integer key.

public class ScriptableRepository<T> : IRepository<T> where T : class, IPrimaryKey<int>, new()

Type Parameters​

NameTypeDescription
TThe type of the entity managed by this repository. Must be a class, implement IPrimaryKey, and have a parameterless constructor.

Inheritance​

Implements​

IRepository<T>

Constructors​

ScriptableRepository(IDatabaseContext)​

Initializes a new instance of the ScriptableRepository class.

public ScriptableRepository(IDatabaseContext context)

Parameters​

NameTypeDescription
contextIDatabaseContextThe database context to use for data operations.

Methods​

Delete(T)​

Deletes the specified entity from the database.

public void Delete(T entity)

Parameters​

NameTypeDescription
entityTThe entity to delete.

ReadAll()​

Retrieves all entities of type T from the database.

public List<T> ReadAll()

Returns​

List<T> — A list of all entities.

ReadByID(int)​

Retrieves an entity by its unique identifier.

public T ReadByID(int id)

Parameters​

NameTypeDescription
idintThe unique identifier of the entity.

Returns​

T — The entity if found; otherwise, null.

Write(T)​

Persists the given entity to the database. If the entity does not exist, it will be inserted;
if it already exists, it will be replaced.

public void Write(T entity)

Parameters​

NameTypeDescription
entityTThe entity to write.
  • Constructors
    • ScriptableRepository(IDatabaseContext)
  • Methods
    • Delete(T)
    • ReadAll()
    • ReadByID(int)
    • Write(T)