Class RelationStore
Implements
Inherited Members
Namespace: DataWeb.Structure.SqlServer
Assembly: DataWeb.Data.SqlServer.dll
Syntax
public class RelationStore : IRelationStore
Constructors
RelationStore(ISqlHelper, IConfigurationService)
Declaration
public RelationStore(ISqlHelper sqlHelper, IConfigurationService configurationService)
Parameters
| Type | Name | Description |
|---|---|---|
| ISqlHelper | sqlHelper | |
| IConfigurationService | configurationService |
Properties
Name
Gets the name of the store.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
ExistsAsync(string, string, string, CancellationToken)
Determines whether a relation exists between a parent and child item in a specific section.
Declaration
public Task<bool> ExistsAsync(string itemIdMaster, string parentIdMaster, string sectionName, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the child item. |
| string | parentIdMaster | The unique identifier of the parent item. |
| string | sectionName | The name of the section containing the relation. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<bool> | True if the relation exists; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when any of the parameters is null or empty. |
GetAncestorsAsync(string, CancellationToken)
Recursively retrieves all ancestor items up the hierarchy for a specific item.
Declaration
public Task<IEnumerable<Relation>> GetAncestorsAsync(string itemIdMaster, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the item to find ancestors for. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<Relation>> | A collection of Relation objects representing the ancestor chain (parents, grandparents, etc.). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when itemIdMaster is null or empty. |
GetChildrenAsync(string, string, CancellationToken)
Retrieves all direct children of an item, optionally filtered by section.
Declaration
public Task<IEnumerable<Relation>> GetChildrenAsync(string itemIdMaster, string sectionName = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the parent item. |
| string | sectionName | The optional section name filter; if null, returns children from all sections. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<Relation>> | A collection of Relation objects representing the direct children, ordered by position. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when itemIdMaster is null or empty. |
GetCountAsync(string, CancellationToken)
Retrieves the total count of relations for a specific item.
Declaration
public Task<long> GetCountAsync(string itemIdMaster, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the item. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<long> | The count of relations for the item. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when itemIdMaster is null or empty. |
GetDescendantsAsync(string, CancellationToken)
Recursively retrieves all descendant items down the hierarchy for a specific item.
Declaration
public Task<IEnumerable<Relation>> GetDescendantsAsync(string itemIdMaster, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the item to find descendants for. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<Relation>> | A collection of Relation objects representing all descendants (children, grandchildren, etc.). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when itemIdMaster is null or empty. |
GetRelationAsync(RelationFilter, CancellationToken)
Retrieves a single relation matching the specified filter criteria.
Declaration
public Task<Relation> GetRelationAsync(RelationFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| RelationFilter | filter | The filter criteria to apply when retrieving the relation. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<Relation> | The first Relation matching the filter, or null if no match found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
GetRelationsAsync(RelationFilter, CancellationToken)
Retrieves relations matching the specified filter criteria with optional pagination and ordering.
Declaration
public Task<IEnumerable<Relation>> GetRelationsAsync(RelationFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| RelationFilter | filter | The filter criteria including IdMaster, ParentIdMaster, SectionName, Count, and ReferenceMode. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<Relation>> | A collection of Relation objects matching the filter criteria. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
MoveAsync(string, string, RelationMoveMode, string, string, int, CancellationToken)
Moves an item relative to a target item within the same parent and section, reordering position values.
Declaration
public Task MoveAsync(string itemIdMaster, string targetIdMaster, RelationMoveMode mode, string parentIdMaster, string sectionName, int movingItemsCount, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the item to move. |
| string | targetIdMaster | The unique identifier of the reference/target item for positioning. |
| RelationMoveMode | mode | The move direction (Up or Down) relative to the target. |
| string | parentIdMaster | The unique identifier of the parent item. |
| string | sectionName | The name of the section. |
| int | movingItemsCount | The count of items being moved together (used for position interpolation). |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when any string parameter is null or empty. |
RemoveAsync(string, string, string, CancellationToken)
Deletes a specific relation between a parent and child item in a section.
Declaration
public Task RemoveAsync(string itemIdMaster, string parentIdMaster, string sectionName, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the child item. |
| string | parentIdMaster | The unique identifier of the parent item. |
| string | sectionName | The name of the section containing the relation. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when any of the parameters is null or empty. |
RemoveAsync(string, CancellationToken)
Deletes all relations for a specific item (removes item from all parent relationships).
Declaration
public Task RemoveAsync(string itemIdMaster, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the item to remove from all relations. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when itemIdMaster is null or empty. |
SaveAsync(string, string, string, CancellationToken)
Creates a new relation between a parent and child item in a specific section, with automatic position calculation.
Declaration
public Task SaveAsync(string itemIdMaster, string parentIdMaster, string sectionName, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | itemIdMaster | The unique identifier of the child item. |
| string | parentIdMaster | The unique identifier of the parent item. |
| string | sectionName | The name of the section to create the relation in. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when any of the parameters is null or empty. |
UpdatePositionAsync(string, double, CancellationToken)
Updates the position (ordering) of a specific relation.
Declaration
public Task UpdatePositionAsync(string Id, double position, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | Id | The unique identifier of the relation to update. |
| double | position | The new position value (numeric ordering). |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when Id is null or empty. |