Class EntityDescriptor
This is the main entity descriptor class that contains all the information about a given entity.
The system automatically creates these entitydescriptors for all entities in the system dynamically from their EntityDefinition and associated attributes
Inheritance
Implements
Inherited Members
Namespace: LemonEdge.Core.Descriptors
Assembly: API.dll
Syntax
public class EntityDescriptor : IQueryableItem
Remarks
The system uses this to understand the schema and other settings of an entity to dynamically interact with it at run time, this includes:
- Database Updates: Creates and upgrades the database table, auditing, permission and associated tables. Also maintains all constraints, indexes, functions and stored procedures.
- Auditing: Automatically audits all changes against an entity
- Querying: Using the schema from this descriptor can understand how users can query and join the data into other queries. Integrates with all querying tools.
- Import/Export: Ensures the system can automatically take care of importing/exporting all data associated with this entity
- UI: Can dynamically create grids and views for the entity from simply listing the required properties
All entities are accesible from EntityDescriptorFactory
Fields
HISTORY_TABLENAME_POSTFIX
The table name postfix given to the history table that all entities also have created for them
Declaration
public const string HISTORY_TABLENAME_POSTFIX = "_History"
Field Value
Type | Description |
---|---|
System.String |
Properties
AutoCreateClusteredIndexes
Indicates if the system will automatically create clustered indexes on the sql database table for this entity
Set from AutoClusteredIndexes
Declaration
public bool AutoCreateClusteredIndexes { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
AutoCreatePrimaryKey
Indicates if the system will automatically create the unique primary key index for this table
Set from AutoCreatePrimaryIndex
Declaration
public bool AutoCreatePrimaryKey { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ContainsPermissions
Indicates if this entity contains its own definition of permissions, or false if it inherits permissions through relationships from parent entities
Declaration
public bool ContainsPermissions { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
CustomToString
Indicates the class implementation of this entity has its own custom string implementation and the system should not automatically generate one returning the label property value
Set from CustomToString
Declaration
public bool CustomToString { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
DefaultColor
The default color to use for this entity in the entity structure mapping diagram
Set from EntityColor
Declaration
public Color? DefaultColor { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Drawing.Color> |
DefaultIconID
The default icon for this entity to be used in the UI
Set from DefaultEntityIcon
Declaration
public Guid DefaultIconID { get; set; }
Property Value
Type | Description |
---|---|
System.Guid |
DontPromoteFromCanvas
By default all entities can be promoted from a canvas into the real system. This can be overriden to prevent that behaviour
Set from DontPromoteFromCanvas
Declaration
public bool DontPromoteFromCanvas { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
EntityType
The entity class that implements the InterfaceType that describes this entity
Our auto-code designers, or tools, can create this code for you
Declaration
public Type EntityType { get; set; }
Property Value
Type | Description |
---|---|
System.Type |
HasAutoIncColumn
Returns true if any of the Properties in this entity are set as having a AutoIncrementColumn
Declaration
public bool HasAutoIncColumn { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
HelpURL
An optional url that holds a help file describing the purpose and functionality of this entity record
Set from HelpURL
Declaration
public string HelpURL { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Indexes
A list of all indexes against this entity descriptor
Set from EntityIndex
Declaration
public TableIndex[] Indexes { get; set; }
Property Value
Type | Description |
---|---|
TableIndex[] |
InheritsFrom
Holds the entity this entity inherits from, if any
Declaration
public EntityDescriptor InheritsFrom { get; }
Property Value
Type | Description |
---|---|
EntityDescriptor |
InheritsFromName
If InheritsFrom holds a value this returns its ItemName
Declaration
public string InheritsFromName { get; }
Property Value
Type | Description |
---|---|
System.String |
InheritsPermissions
Returns true if any of the Relationships on this entity descriptor are set to inherit permissions from that relationship
Declaration
public bool InheritsPermissions { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
InterfaceType
The interface type that holds the definition for this entity
Declaration
public Type InterfaceType { get; set; }
Property Value
Type | Description |
---|---|
System.Type |
IsAddInEntityDescriptor
Indicates this entity descriptor is loaded as an addin
Declaration
public bool IsAddInEntityDescriptor { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsBaseEntity
Returns true if this entity implements IBaseObject
Declaration
public bool IsBaseEntity { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsCustomEntityDescriptor
Indicates this entity descriptor is loaded as a custom entity
Declaration
public bool IsCustomEntityDescriptor { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsCustomOrAddInEntityDescriptor
Indicates this entity descriptor is not part of the "core" system and rather is loaded as an addin/custom dll
Declaration
public bool IsCustomOrAddInEntityDescriptor { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsInheritingEntity
Returns true if this entity implements IInheritingObject
Declaration
public bool IsInheritingEntity { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsSetCopier
Indicates if this entity implements the ISetCopier interface
Declaration
public bool IsSetCopier { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsSP
Indicates this queryableitem can only be queried from within a stored procedure. For entity descriptors this is always false.
Declaration
public bool IsSP { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsStandingDataEntity
Indicates this entity is part of the standing data/configuation for the system It should be loaded on application startup as part of the cache. Do not use for tables of large data sets
Declaration
public bool IsStandingDataEntity { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
ItemName
The name the system should use when referring to an instance of this entity.
This should contain alpha numerical characters only, not spaces or other special characters
Set from ItemNameDeclaration
public string ItemName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ItemNameWithReplicatedDescriptor
Returns the item name for this entity including any replicated descriptor from ReplicatedFrom
Declaration
public string ItemNameWithReplicatedDescriptor { get; }
Property Value
Type | Description |
---|---|
System.String |
LabelColumn
Holds the name of the property that holds the label to be used for any instance of this entity in the ui. Not required, items can have no label, though standing data entities should avoid not having one.
Set from LabelColumn
Declaration
public string LabelColumn { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Name
The name of this queryable item Holds the itemname with replicated descriptor if there is one
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
OldTableNames
A list of tablenames this entity used to have
Set from TableName
Declaration
public IEnumerable<EntityDefintionOldInfo> OldTableNames { get; set; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<EntityDefintionOldInfo> |
ParentToAnyRelationships
A list of relationships that can have any parent as the target of the relationship
Declaration
public EntityRelationship[] ParentToAnyRelationships { get; set; }
Property Value
Type | Description |
---|---|
EntityRelationship[] |
PivotInfo
Holds pivot information if this entity is defined as having pivot information from EntityHasPivotAttribute
Declaration
public PivotTableInfo PivotInfo { get; set; }
Property Value
Type | Description |
---|---|
PivotTableInfo |
Properties
A list of all the properties against the interface/entity defined by this entitydescriptor
Declaration
public ColumnDescriptor[] Properties { get; set; }
Property Value
Type | Description |
---|---|
ColumnDescriptor[] |
Relationships
A list of all relationships from this entity to other entities in the system
Set from PropRelationship attributes
Declaration
public EntityRelationship[] Relationships { get; set; }
Property Value
Type | Description |
---|---|
EntityRelationship[] |
ReplicatedColumn
If this entity is replicated from another entity, this holds the column that refers to the entity type it is replicated from
Declaration
public ColumnDescriptor ReplicatedColumn { get; }
Property Value
Type | Description |
---|---|
ColumnDescriptor |
ReplicatedFrom
Holds the entity this entity is replicated from, if any
Declaration
public EntityDescriptor ReplicatedFrom { get; set; }
Property Value
Type | Description |
---|---|
EntityDescriptor |
ReplicatedFromName
If ReplicatedFrom holds a value this returns its ItemName
Declaration
public string ReplicatedFromName { get; }
Property Value
Type | Description |
---|---|
System.String |
SelectWithNoLock
Indicates this table should always select information from it with no locking. This can be set for performance reasons for tables that do not update, such as audit tables.
Set from SelectWithNoLock
Declaration
public bool SelectWithNoLock { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
SetName
The name the system should use when referring to a collection of these entities
This should contain alpha numerical characters only, not spaces or other special characters
Set from SetNameDeclaration
public string SetName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
SetNameWithReplicatedDescriptor
Returns the set name for this entity including any replicated descriptor from ReplicatedFrom
Declaration
public string SetNameWithReplicatedDescriptor { get; }
Property Value
Type | Description |
---|---|
System.String |
TableName
The table name for this entity descriptor
Set from TableName
Declaration
public string TableName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
TableNameHistory
Holds the table name for this entities audit history table
Declaration
public string TableNameHistory { get; }
Property Value
Type | Description |
---|---|
System.String |
TableNameWithoutPrefix
Holds the table name for this entity without the dbo prefix
Declaration
public string TableNameWithoutPrefix { get; }
Property Value
Type | Description |
---|---|
System.String |
TableNameWithoutPrefixHistory
Holds the table name for this entities audit history table without the dbo prefix
Declaration
public string TableNameWithoutPrefixHistory { get; }
Property Value
Type | Description |
---|---|
System.String |
TopName
If this queryable item has a subid, then the name holds the overall name, but topname holds the name of the queryable item type at the top level For instance with entities, with transactions in entities id holds the id for transactions, and name would hold transaction with permissions in entities id holds the id for permissions, sub id would hold the entity against which it holds permissions, name would hold Entity_Permission and topname would hold Permissions so we know the type is permissions
Declaration
public string TopName { get; }
Property Value
Type | Description |
---|---|
System.String |
TrackAllChanges
Returns true if any of the Properties have been marked with DBTrackChangesAttribute
Declaration
public bool TrackAllChanges { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
TypeID
The unique type id for this entity. Every entity definition in the system must have a unique global id for that entity type
Declaration
public Guid TypeID { get; set; }
Property Value
Type | Description |
---|---|
System.Guid |
TypeSubID
If this entity has been replicated from another entity descriptor, the sub type holds the replicated entity globally unique type id
Declaration
public Guid? TypeSubID { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Guid> |
UniqueKey
The unique key of this entity descriptor which is a combination of its TypeID and ReplicatedFrom TypeID if it has one
Declaration
public string UniqueKey { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
BelongsToDescriptor(IBaseEntity)
Returns true if the specified item belongs to this entity descriptor.
This includes taking into account if this descriptor is replicated from a replicated entity descriptor
Declaration
public bool BelongsToDescriptor(IBaseEntity item)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | item | The item to check if this entity descriptor describes everything about it. |
Returns
Type | Description |
---|---|
System.Boolean | True if the specified item belongs to this entity descriptor. |
CreateNew(UserInfo)
Creates a new instance of the EntityType for this entity while also setting any properties to their configured hardcoded or formula default values
Declaration
public Task<IBaseEntity> CreateNew(UserInfo createdBy)
Parameters
Type | Name | Description |
---|---|---|
UserInfo | createdBy | The currently logged in (or active) user that is creating this new item |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IBaseEntity> | A new instance of the EntityType for this entity while also setting any properties to their configured hardcoded or formula default values |
CreateParentRelationshipForParentType(EntityRelationship, EntityDescriptor)
Creates a relationship from the specific relationship to any parent and the specific parent entity type
Declaration
public EntityRelationship CreateParentRelationshipForParentType(EntityRelationship parentToAnyRelationship, EntityDescriptor parentType)
Parameters
Type | Name | Description |
---|---|---|
EntityRelationship | parentToAnyRelationship | The relationship that can have any antity as a parent target |
EntityDescriptor | parentType | The entity to be the target of the relationship |
Returns
Type | Description |
---|---|
EntityRelationship | A new specific relationship from the source entity to the specific parent entity |
CreateRelationships(EntityDescriptor, ICustomObject, IEnumerable<ICustomObjectProperty>, IEnumerable<EntityDescriptor>)
Creates all the relationships for the entitydescriptor created for a custom object
Declaration
public static void CreateRelationships(EntityDescriptor desc, ICustomObject obj, IEnumerable<ICustomObjectProperty> props, IEnumerable<EntityDescriptor> customDescriptiors)
Parameters
Type | Name | Description |
---|---|---|
EntityDescriptor | desc | The entity descriptor that describes a custom object |
ICustomObject | obj | The custom object |
System.Collections.Generic.IEnumerable<ICustomObjectProperty> | props | All properties for the custom object (which include relationship definitions) |
System.Collections.Generic.IEnumerable<EntityDescriptor> | customDescriptiors | All other entity descriptors in the system (including other custom object entity descriptors) |
CreateTempFrom(ICustomObject, IEnumerable<ICustomObjectProperty>)
Creates a temporary entitydescriptor for the specified auto-code designed ICustomObject
Declaration
public static EntityDescriptor CreateTempFrom(ICustomObject customObj, IEnumerable<ICustomObjectProperty> props)
Parameters
Type | Name | Description |
---|---|---|
ICustomObject | customObj | The auto-code designed custom object |
System.Collections.Generic.IEnumerable<ICustomObjectProperty> | props | The properties designed against this custom object |
Returns
Type | Description |
---|---|
EntityDescriptor | A temporary entitydescriptor for the specified auto-code designed ICustomObject |
GetFields(IReadOnlyCache)
Returns all fields that can be queried from this queryable item
Declaration
public Task<IEnumerable<IQueryableFieldInfo>> GetFields(IReadOnlyCache cache)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyCache | cache | A local context cache |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<IQueryableFieldInfo>> | For all entities this returns all properties that exist in sql against this entity, unless this entity implements a EntityDescriptorTemplateExtender in which case it returns the fields |
GetIDsFromUniqueKey(String)
Parses a unique key to return the TypeID and Replicated Type ID (if there is one)
Declaration
public static (Guid TypeID, Guid? ReplicatedSubID) GetIDsFromUniqueKey(string uniqueKey)
Parameters
Type | Name | Description |
---|---|---|
System.String | uniqueKey | A unique key from an UniqueKey |
Returns
Type | Description |
---|---|
System.ValueTuple<System.Guid, System.Nullable<System.Guid>> |
GetInheritingDescriptors()
Returns a list of all entities in the system that inherit from this entity
Declaration
public IEnumerable<EntityDescriptor> GetInheritingDescriptors()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<EntityDescriptor> | A list of all entities in the system that inherit from this entity |
GetItemNameWithReplicatedDescriptor(String, String)
Returns the name of the item name to use from an entity descriptor item name, and the item name from another entity descriptor that holds the replicated item name
Replicated entitydescriptors are created for each entity descriptor in the system. For instance the permissions entity descriptor is replicated for every entity in the system
Declaration
public static string GetItemNameWithReplicatedDescriptor(string itemName, string replicatedFromItemName)
Parameters
Type | Name | Description |
---|---|---|
System.String | itemName | The name of the item from an entity descriptor |
System.String | replicatedFromItemName | The name of an item from the replicated entity descriptor. Can be null if no replicated descriptor. |
Returns
Type | Description |
---|---|
System.String | The item name to use for the replicated entity descriptor |
GetParams(IReadOnlyCache)
Returns all parameters that need to be used in order to call this queryable item
Declaration
public Task<IEnumerable<IQueryableParamInfo>> GetParams(IReadOnlyCache cache)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyCache | cache | A local context cache |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<IQueryableParamInfo>> | For all entities this includes the following parameters: AccountID, CanvasID, TeamID, and LastUpdated |
GetReplicatedDescriptors(Boolean)
Provides all descriptors that have been replicated from this one
Declaration
public IEnumerable<EntityDescriptor> GetReplicatedDescriptors(bool createTempIfNoExistForReplicator)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | createTempIfNoExistForReplicator | If a replicating descriptor isn't created for this descriptor (i.e. not all entities have a permission replicated for them if they inherit permissions instead) setting this flag to true would return a temporary one anyway for reference. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<EntityDescriptor> |
GetReverseRelationships(Boolean)
Returns a list of all relationships from other entities in the system that have this entity as a target
Declaration
public IEnumerable<EntityRelationship> GetReverseRelationships(bool includeParentToAnyRelationships = true)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | includeParentToAnyRelationships | Indicates relationships that can have any parent entity as a target should also be included |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<EntityRelationship> | A list of all relationships from other entities in the system that have this entity as a target |
GetSetNameWithReplicatedDescriptor(String, String)
Returns the name of the set name to use from an entity descriptor set name, and the set name from another entity descriptor that holds the replicated set name
Replicated entitydescriptors are created for each entity descriptor in the system. For instance the permissions entity descriptor is replicated for every entity in the system
Declaration
public static string GetSetNameWithReplicatedDescriptor(string setName, string replicatedFromItemName)
Parameters
Type | Name | Description |
---|---|---|
System.String | setName | The name of the set from an entity descriptor |
System.String | replicatedFromItemName | The name of an item from the replicated entity descriptor. Can be null if no replicated descriptor. |
Returns
Type | Description |
---|---|
System.String | The set name to use for the replicated entity descriptor |
GetSQLToSelectFrom(Int64, IEnumerable<(IQueryableParamInfo Param, String SQLValue)>)
Returns the sql function/table to call to return the data for this queryable item
Declaration
public string GetSQLToSelectFrom(long accountID, IEnumerable<(IQueryableParamInfo Param, string SQLValue)> sqlParams)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | accountID | The account id this sql is being generated for |
System.Collections.Generic.IEnumerable<System.ValueTuple<IQueryableParamInfo, System.String>> | sqlParams | The valuesof any sql parameters used to call this queryable item |
Returns
Type | Description |
---|---|
System.String | For all entities this returns the call to the default function for this entity, unless this entity implements a EntityDescriptorTemplateExtender in which case it returns the sql call |
GetTableNameWithReplicated(String, String)
Returns the name of the table to use from an entity descriptor tabe name, and the table name from another entity descriptor that holds the replicated table name
Replicated entitydescriptors are created for each entity descriptor in the system. For instance the permissions entity descriptor is replicated for every entity in the system
Declaration
public static string GetTableNameWithReplicated(string tableName, string replicatedTableName)
Parameters
Type | Name | Description |
---|---|---|
System.String | tableName | The name of the table from an entity descriptor |
System.String | replicatedTableName | The name of a table from the replicated entity descriptor. Can be null if no replicated descriptor. |
Returns
Type | Description |
---|---|
System.String | The table name to use for the replicated entity descriptor |
IsCoreOrPartOfSpecificCustomAssembly(IEnumerable<Assembly>)
Indicates if this entity is part of the core or a set of specific assemblies (usually the ones currently loaded through addins)
Declaration
public bool IsCoreOrPartOfSpecificCustomAssembly(IEnumerable<Assembly> customAssemblies)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | customAssemblies | A list of specific assemblies the entity can be a type from |
Returns
Type | Description |
---|---|
System.Boolean | True if this entity is part of the core or a set of specific assemblies (usually the ones currently loaded through addins) |
NonInheritedProperties()
A list of all Properties against this interface/entity that is not inherited from a base type
Declaration
public IEnumerable<ColumnDescriptor> NonInheritedProperties()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ColumnDescriptor> | A list of all Properties against this interface/entity that is not inherited from a base type |
ReplicateForAll(String, String, Int64, IEnumerable<(IQueryableParamInfo Param, String SQLValue)>)
If this queryable item is being replicated for all then this returns a sqlselect string for each replication
Declaration
public IEnumerable<string> ReplicateForAll(string dbKeyForEntityDescriptors, string originalSQLToSelectFrom, long accountID, IEnumerable<(IQueryableParamInfo Param, string SQLValue)> sqlParams)
Parameters
Type | Name | Description |
---|---|---|
System.String | dbKeyForEntityDescriptors | The db key this sql is being generated for |
System.String | originalSQLToSelectFrom | The original sql to select from |
System.Int64 | accountID | The current account id this sql is being generated for |
System.Collections.Generic.IEnumerable<System.ValueTuple<IQueryableParamInfo, System.String>> | sqlParams | The valuesof any sql parameters used to call this queryable item |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> | If this entity is ReplicatedFrom then this returns the generated sql for each different entity that is also replicated from the same replicated entity |
ShallowClone(UserInfo, IBaseEntity)
Creates a new item that has the same values for all entity defined properties as the specified sourceItem
Declaration
public Task<IBaseEntity> ShallowClone(UserInfo createdBy, IBaseEntity sourceItem)
Parameters
Type | Name | Description |
---|---|---|
UserInfo | createdBy | The currently logged in (or active) user that is creating this new item |
IBaseEntity | sourceItem | The item to copy all defined property values from |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IBaseEntity> | A new item that has the same values for all entity defined properties as the specified |
ToString()
Returns the SetName for this entity descriptor
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | The SetName for this entity descriptor |
Overrides
Explicit Interface Implementations
IQueryableItem.ID
The unique id of this queryable item. Holds the unique type id of this entity
Declaration
string IQueryableItem.ID { get; }
Returns
Type | Description |
---|---|
System.String |
IQueryableItem.SubID
The sub id for this queryable item. Will hold the replicated id if there is one.
Declaration
string IQueryableItem.SubID { get; }
Returns
Type | Description |
---|---|
System.String |