Class HasRelationshipField<T, TDeserialization>
- Namespace
- AbanoubNassem.Trinity.Components.TrinityField
- Assembly
- AbanoubNassem.Trinity.dll
A base class for fields that have a relationship with another table.
public abstract class HasRelationshipField<T, TDeserialization> : TrinityField<HasRelationshipField<T, TDeserialization>, TDeserialization>, ITrinityComponent, ITrinityField, IFormComponent, IHasRelationship
Type Parameters
T
The type of the field.
TDeserialization
The type of the deserialization.
- Inheritance
-
TrinityComponent<HasRelationshipField<T, TDeserialization>, TDeserialization>TrinityField<HasRelationshipField<T, TDeserialization>, TDeserialization>HasRelationshipField<T, TDeserialization>
- Implements
- Derived
- Inherited Members
Constructors
HasRelationshipField(string, string?, string?)
Initializes a new instance of the HasRelationshipField<T, TDeserialization> class.
protected HasRelationshipField(string columnName, string? foreignColumn = null, string? foreignTable = null)
Parameters
columnName
stringThe name of the column.
foreignColumn
stringThe name of the foreign column.
foreignTable
stringThe name of the foreign table.
Properties
ForeignColumn
Gets or sets the name of the foreign column for the relationship.
public string? ForeignColumn { get; set; }
Property Value
ForeignTable
Gets or sets the name of the foreign table.
public string? ForeignTable { get; set; }
Property Value
- string
The name of the foreign table.
HasRelationshipByDefault
A boolean that indicates whether this column has a relationship by default.
public bool HasRelationshipByDefault { get; set; }
Property Value
Lazy
Gets or sets a value indicating whether this field should be lazy-loaded.
public bool Lazy { get; protected set; }
Property Value
- bool
true
if this field should be lazy-loaded; otherwise,false
.
LazyItemsCount
Gets or sets the number of items to load lazily.
public int LazyItemsCount { get; protected set; }
Property Value
- int
The number of items to load lazily.
RelationshipName
The name of the relationship.
public string? RelationshipName { get; set; }
Property Value
Methods
FilterQuery(Query, string)
Adds a filter query for the field to a query builder.
public override void FilterQuery(Query query, string globalSearch)
Parameters
query
QueryThe query builder to use.
globalSearch
string
GetAssociatesRelationshipQuery(QueryFactory, string?, int, string?)
A method that gets the associates relationship query using the specified queryFactory, value, offset, search string, and returns a list of the key-value pairs.
public virtual Task<List<KeyValuePair<string, string>>> GetAssociatesRelationshipQuery(QueryFactory queryFactory, string? value, int offset, string? search = null)
Parameters
queryFactory
QueryFactoryThe query factory used to create the query
value
stringThe value to search for, if any.
offset
intThe offset to use
search
stringThe search string to use
Returns
- Task<List<KeyValuePair<string, string>>>
A list of key-value pairs
SelectQuery(Query)
Adds a select query for the field to a query builder.
public override void SelectQuery(Query query)
Parameters
query
QueryThe query builder to use.
SelectRelationshipQuery(QueryFactory, List<IDictionary<string, object?>>, Sort?)
A method that selects the relationship query using the specified queryFactory and list of records, returns a list of the selected relationships.
public abstract Task<List<IDictionary<string, object?>>> SelectRelationshipQuery(QueryFactory queryFactory, List<IDictionary<string, object?>> records, Sort? sort = null)
Parameters
queryFactory
QueryFactoryThe query factory used to create the query
records
List<IDictionary<string, object>>The list of records to select from
sort
SortThe sorting object
Returns
- Task<List<IDictionary<string, object>>>
A list of selected relationships
SetAsLazy(bool, int)
Sets whether this field should be lazy-loaded and the number of items to load lazily.
public HasRelationshipField<T, TDeserialization> SetAsLazy(bool lazy = true, int lazyItemsCount = 10)
Parameters
lazy
boolWhether this field should be lazy-loaded.
lazyItemsCount
intThe number of items to load lazily.
Returns
- HasRelationshipField<T, TDeserialization>
The current instance of the HasRelationshipField<T, TDeserialization> field.
SetForeignColumn(string)
Sets the name of the foreign column for this field.
public HasRelationshipField<T, TDeserialization> SetForeignColumn(string value)
Parameters
value
stringThe name of the foreign column.
Returns
- HasRelationshipField<T, TDeserialization>
The current instance of the HasRelationshipField<T, TDeserialization> field.
SetForeignTable(string)
Sets the name of the foreign table for this field.
public HasRelationshipField<T, TDeserialization> SetForeignTable(string value)
Parameters
value
stringThe name of the foreign table.
Returns
- HasRelationshipField<T, TDeserialization>
The current instance of the HasRelationshipField<T, TDeserialization> field.
SetRelationshipName(string)
Sets the name of the relationship for this field.
public HasRelationshipField<T, TDeserialization> SetRelationshipName(string value)
Parameters
value
stringThe name of the relationship.
Returns
- HasRelationshipField<T, TDeserialization>
The current instance of the HasRelationshipField<T, TDeserialization> field.