Class EntityDetailsHelper<TParent, TChild>
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Inheritance
Implements
Inherited Members
Namespace: SuperOffice.CRM.Entities
Assembly: SoDataBase.dll
Syntax
public abstract class EntityDetailsHelper<TParent, TChild> : NestedPersistFacade, INestedPersist where TParent : class, INestedPersist where TChild : class, INestedPersist
Type Parameters
| Name | Description |
|---|---|
| TParent | Type of parent, normally a row or entity. |
| TChild | Type of child, normally a row or entity. |
Constructors
EntityDetailsHelper(TParent)
Constructor called by the implementation
Declaration
protected EntityDetailsHelper(TParent parent)
Parameters
| Type | Name | Description |
|---|---|---|
| TParent | parent | Parent object owning the children. |
Properties
Children
Get all the child items.
Declaration
protected TChild[] Children { get; }
Property Value
| Type | Description |
|---|---|
| TChild[] |
IsDirty
Is the object dirty?
Declaration
public override bool IsDirty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Overrides
Items
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected List<TChild> Items { get; }
Property Value
| Type | Description |
|---|---|
| List<TChild> |
Parent
Get the parent object.
Declaration
protected TParent Parent { get; }
Property Value
| Type | Description |
|---|---|
| TParent |
RemovedItems
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected List<TChild> RemovedItems { get; }
Property Value
| Type | Description |
|---|---|
| List<TChild> |
Methods
Add(TChild)
Add a child to the collection.
Declaration
protected TChild Add(TChild child)
Parameters
| Type | Name | Description |
|---|---|---|
| TChild | child | Instance of the child to add. |
Returns
| Type | Description |
|---|---|
| TChild | The item actually added. |
Remarks
Override IsSameChild(TChild, TChild) if a custom implementation is required for comparing two child items. This is used when checking if the child was previously removed and now can be re-added.
Edit(TChild)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected void Edit(TChild child)
Parameters
| Type | Name | Description |
|---|---|---|
| TChild | child |
FindChildInItems(ref TChild)
Find a child in the list of items and return the found one. Note that IsSameChild(TChild, TChild) is called to determine equivalence, so that the found instance may be different from the one being looked for.
Declaration
protected bool FindChildInItems(ref TChild foundEquivalent)
Parameters
| Type | Name | Description |
|---|---|---|
| TChild | foundEquivalent | Child to search for, updated with the one actually found |
Returns
| Type | Description |
|---|---|
| bool | True if there exists an equivalent child to the one searched for. |
GetFacadingItems()
Implement this method to expose items that needs to be persisted.
Declaration
protected override IEnumerable<INestedPersist> GetFacadingItems()
Returns
| Type | Description |
|---|---|
| IEnumerable<INestedPersist> | Collection of items that needs to be persisted. |
Overrides
IsSameChild(TChild, TChild)
Determine if two children are the same. This base implementation uses the == operator if the child type; override if you need different behaviour (see IsSameChild(RelationsRow, RelationsRow) for an example override).
Declaration
protected virtual bool IsSameChild(TChild child1, TChild child2)
Parameters
| Type | Name | Description |
|---|---|---|
| TChild | child1 | |
| TChild | child2 |
Returns
| Type | Description |
|---|---|
| bool |
LoadChildItemsAsync(TParent, CancellationToken)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
public abstract Task LoadChildItemsAsync(TParent parent, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| TParent | parent | |
| CancellationToken | cancellationToken |
Returns
| Type | Description |
|---|---|
| Task |
OnChildIdUpdate(TParent, TChild, bool)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected abstract void OnChildIdUpdate(TParent parent, TChild child, bool isRemoved)
Parameters
| Type | Name | Description |
|---|---|---|
| TParent | parent | |
| TChild | child | |
| bool | isRemoved |
OnChildPreIdUpdate(TParent, TChild, bool)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected abstract void OnChildPreIdUpdate(TParent parent, TChild child, bool isRemoved)
Parameters
| Type | Name | Description |
|---|---|---|
| TParent | parent | |
| TChild | child | |
| bool | isRemoved |
OnIdUpdateAsync()
Update related objects with correct id's to make sure that relations are consistent before saving to the database.
Declaration
protected override Task OnIdUpdateAsync()
Returns
| Type | Description |
|---|---|
| Task |
Overrides
OnParentIdUpdate(TParent)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected virtual void OnParentIdUpdate(TParent parent)
Parameters
| Type | Name | Description |
|---|---|---|
| TParent | parent |
OnParentPreIdUpdate(TParent)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected virtual void OnParentPreIdUpdate(TParent parent)
Parameters
| Type | Name | Description |
|---|---|---|
| TParent | parent |
OnPreIdUpdateAsync()
Allow for "fake id's" to be forced upon related objects.
Declaration
protected override Task OnPreIdUpdateAsync()
Returns
| Type | Description |
|---|---|
| Task |
Overrides
Remarks
In order to figure out which objects taking part of the nested save operation that actually needs to be saved, this method allows for "fake id's" to be forced upon related objects. Upon receiving the "fake id", the objects receiving such an id can determine if they needs to be persisted (e.g. saved) to the database. However, the fake id's forced upon related objects must be set to correct id's in the OnIdUpdate method taking place later in the save operation.
OnSavedAsync(bool)
Called after the save operation has completed. A boolean value is passed to notify whether or not the save operation succeeded. The complete save operation is rolled back if Save operation failed.
Declaration
protected override Task OnSavedAsync(bool bSucceeded)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | bSucceeded | True if the save operation succeeded and false if the save operation failed and rolled back. |
Returns
| Type | Description |
|---|---|
| Task |
Overrides
Remove(TChild)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected void Remove(TChild child)
Parameters
| Type | Name | Description |
|---|---|---|
| TChild | child |
SetChildren(params TChild[])
Set the desired new children collection. This method uses the virtual IsSameChild(TChild, TChild) to compare each incoming child with existing children, and determines children to be added, removed or left unchanged. It will only add children that are new according to IsSameChild regardless of whether the underlying TChild instances are the same. Existing children that are not in the new set are marked for deletion, but may be resurrected by a later SetChildren or AddChild call.
Declaration
protected void SetChildren(params TChild[] children)
Parameters
| Type | Name | Description |
|---|---|---|
| TChild[] | children | Children that should be the new set |
hasChanged(TChild, TChild)
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
protected virtual bool hasChanged(TChild child1, TChild child2)
Parameters
| Type | Name | Description |
|---|---|---|
| TChild | child1 | |
| TChild | child2 |
Returns
| Type | Description |
|---|---|
| bool |
Events
OnEntityDetailsHelperAdded
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
public event EntityDetailsHelperModified<TParent, TChild> OnEntityDetailsHelperAdded
Event Type
| Type | Description |
|---|---|
| EntityDetailsHelperModified<TParent, TChild> |
OnEntityDetailsHelperEdited
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
public event EntityDetailsHelperModified<TParent, TChild> OnEntityDetailsHelperEdited
Event Type
| Type | Description |
|---|---|
| EntityDetailsHelperModified<TParent, TChild> |
OnEntityDetailsHelperRemoved
Helper class for maintaining child items of type INestedPersist belonging to a parent item of type INestedPersist. Remember to call LoadChildItems from your subclass constructor
Declaration
public event EntityDetailsHelperModified<TParent, TChild> OnEntityDetailsHelperRemoved
Event Type
| Type | Description |
|---|---|
| EntityDetailsHelperModified<TParent, TChild> |