Interface IDatabaseContext
Represents a generic database context that provides CRUD operations.
public interface IDatabaseContext
Methods
Create<T>(T)
Inserts a new item into the database.
void Create<T>(T item)
Parameters
| Name | Type | Description |
|---|---|---|
item | T | The item to insert. |
Type Parameters
| Name | Type | Description |
|---|---|---|
T | The type of the item to insert. |
CreateOrUpdate<T>(T)
Inserts a new item or updates an existing one in the database.
void CreateOrUpdate<T>(T item)
Parameters
| Name | Type | Description |
|---|---|---|
item | T | The item to insert or update. |
Type Parameters
| Name | Type | Description |
|---|---|---|
T | The type of the item to insert or update. |
Delete<T>(T)
Deletes the specified item from the database.
void Delete<T>(T item)
Parameters
| Name | Type | Description |
|---|---|---|
item | T | The item to delete. |
Type Parameters
| Name | Type | Description |
|---|---|---|
T | The type of the item to delete. |
DeleteById<T, K>(K)
Deletes an item from the database using its primary key.
void DeleteById<T, K>(K primaryKey)
Parameters
| Name | Type | Description |
|---|---|---|
primaryKey | K | The primary key of the item to delete. |
Type Parameters
| Name | Type | Description |
|---|---|---|
T | The type of the item to delete. | |
K | The type of the primary key. |
Read<T>(Expression<Func<T, bool>>)
Retrieves a single item from the database that matches the specified predicate.
T Read<T>(Expression<Func<T, bool>> predicate) where T : new()
Parameters
| Name | Type | Description |
|---|---|---|
predicate | Expression<Func<T, bool>> | An expression used to filter the item. |
Returns
T — The item that matches the predicate, or null if no match is found.
Type Parameters
| Name | Type | Description |
|---|---|---|
T | The type of the item to read. |