Interface IRepository<T>
Generic repository interface defining basic CRUD operations for a specific entity type.
public interface IRepository<T> where T : class
Type Parameters
| Name | Type | Description |
|---|---|---|
T | The type of the entity managed by the repository. Must be a class. |
Examples
Defining a SQLite-backed entity and performing CRUD via DatabaseConnector.
Implement IPrimaryKey so [GetRepository](../Classes/DatabaseConnector.mdx) accepts the type. The [PrimaryKey][AutoIncrement]` attributes are read by
SQLiteContext to create the backing table correctly; omitting them causes
insert collisions on the integer key column.
// Entity — satisfies the IPrimaryKey and new() constraints:
[SQLite.Table("session_log")]
public class SessionLogEntry : IPrimaryKey
{
[SQLite.PrimaryKey]
[SQLite.AutoIncrement]
public int Id { get; set; }
public string ScenarioName { get; set; }
public float DurationSeconds { get; set; }
}
// Persist a new entry at the end of a scenario:
var repo = DatabaseConnector.Current.GetRepository();
repo.Write(new SessionLogEntry { ScenarioName = "Urban01", DurationSeconds = 134.5f });
// Retrieve a specific entry by its auto-assigned primary key:
SessionLogEntry entry = repo.ReadByID(1);
// Enumerate all entries for post-session export:
List all = repo.ReadAll();
// Remove a stale entry:
repo.Delete(entry);
Methods
Delete(T)
Deletes the specified entity from the database.
void Delete(T entity)
Parameters
| Name | Type | Description |
|---|---|---|
entity | T | The entity to delete. |