Class ModelEntityBase
Acts as the base class for entities in Time Cockpit's data model
Implements
Inherited Members
Namespace: TimeCockpit.Data.DataModel
Assembly: TimeCockpit.Data.dll
Syntax
public abstract class ModelEntityBase : ModelElement, IDynamicMetaObjectProvider, INotifyPropertyChanged, IDataErrorInfo
Remarks
Entities in Time Cockpit's data model can be seen similar to tables in a relation database management system. In fact persisted entities are stored in tables in Time Cockpit's database. However, not every entity needs to have a representation as a table. Applications can create entities during runtime; they can mark these entites as non-persistent (see PersistBehavior.
Constructors
ModelEntityBase()
Initializes a new instance of the ModelEntityBase class.
Declaration
protected ModelEntityBase()
ModelEntityBase(IEnumerable<KeyValuePair<Object, Object>>)
Initializes a new instance of the ModelEntityBase class.
Declaration
protected ModelEntityBase(IEnumerable<KeyValuePair<object, object>> properties)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>> | properties | Collection of properties. |
Remarks
You can use this constructor to initialize a new instance of the ModelElement class by specifying its properties in a list of key/value pairs. This is especially useful for dynamic languages like python.
ModelEntityBase(ModelEntityBase)
Initializes a new instance of the ModelEntityBase class.
Declaration
protected ModelEntityBase(ModelEntityBase element)
Parameters
Type | Name | Description |
---|---|---|
ModelEntityBase | element | The element to copy. |
Remarks
Copy constructor for copying values of an instance of ModelEntityBase. The constructor copies all the values of the value types. ModelEntityInterfaces, Permissions, Triggers, ValidationRules, ModelPropertys and Relations of the ModelEntityBase to copy are just added to the corresponding collections. Please note that if this method is called alone always clones that targets of a relation. It does not preserve the object references. Consider calling the copy constructor of Model.
Properties
AllRelations
Gets the combined view of all physical and logical relations.
Declaration
public CombinedModelCollectionView<RelationBase, Relation, LogicalRelation> AllRelations { get; }
Property Value
Type | Description |
---|---|
CombinedModelCollectionView<RelationBase, Relation, LogicalRelation> |
AuditMode
Gets or sets the audit mode for the given ModelEntityBase.
Declaration
public AuditMode AuditMode { get; set; }
Property Value
Type | Description |
---|---|
AuditMode |
CyclicRelations
Gets the cyclic relations.
Declaration
public Relation[] CyclicRelations { get; }
Property Value
Type | Description |
---|---|
Relation[] |
DefaultDisplayPropertyName
Gets or sets the default property name to display
Declaration
public string DefaultDisplayPropertyName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
DefaultFormName
Gets or sets the default form of the ModelEntityBase.
Declaration
public string DefaultFormName { get; set; }
Property Value
Type | Description |
---|---|
System.String | The name of the default form. |
DefaultListName
Gets or sets the default list of the ModelEntityBase.
Declaration
public string DefaultListName { get; set; }
Property Value
Type | Description |
---|---|
System.String | The name of the default list. |
DefaultRelationListName
Gets or sets the default name of the list that is used when the current instance of ModelEntityBase is displayed in a combobox.
Declaration
public string DefaultRelationListName { get; set; }
Property Value
Type | Description |
---|---|
System.String | The default name of the relation list. |
DependentModelEntities
Gets the dependent model entities in the correct order for deletion.
Declaration
public IEnumerable<Dependency> DependentModelEntities { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Dependency> |
DependentRelationPaths
Gets the dependent relation paths.
Declaration
public IEnumerable<IEnumerable<Relation>> DependentRelationPaths { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<Relation>> |
ImplementedInterfaces
Gets the collection used to store the interfaces implemented by this model entity
Declaration
public ModelCollection<ModelEntityInterface> ImplementedInterfaces { get; }
Property Value
Type | Description |
---|---|
ModelCollection<ModelEntityInterface> |
Remarks
If you need to add/remove implemented interfaces by name (commonly needed in script languages) use AddImplementedInterface(String)/RemoveImplementedInterface(String).
IsDataSynced
Gets a value indicating whether records of a model entity are synced or not
Declaration
public bool IsDataSynced { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsGenericRelationEntity
Gets or sets a value indicating whether this entity should act as a generic relation.
Declaration
public bool IsGenericRelationEntity { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
Generic relations allow to attach the entity to all other entities via a logical, generic link. System entities as well as other generic entities are excluded as possible link targets. The related objects are persisted via non-foreign-key guid properties ("ModelEntityUuid" and "EntityObjectUuid") which are automatically added to the model entity when this flag is set to true. Please be aware that setting this flag to false will not remove those properties.
The access to the related object is implemented by providing transient, non-persisted logical relation. For each possible link target entity a logical relation named like the entity is automatically inserted when the model is being loaded. Additionally we support a virtual property "GenericRelation" which also provides in-memory access to the related object.
IsModelSynced
Gets a value indicating whether the model of a model entity is synced or not
Declaration
public bool IsModelSynced { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
LogicalRelations
Gets the collection of logical relations.
Declaration
public ModelCollection<LogicalRelation> LogicalRelations { get; }
Property Value
Type | Description |
---|---|
ModelCollection<LogicalRelation> |
Permissions
Gets the read permissions of the ModelEntityBase
Declaration
public ModelCollection<Permission> Permissions { get; }
Property Value
Type | Description |
---|---|
ModelCollection<Permission> |
PersistBehavior
Gets or sets a value indicating whether the ModelElement
instance should be persisted in
the database.
Declaration
public override PersistBehavior PersistBehavior { get; set; }
Property Value
Type | Description |
---|---|
PersistBehavior |
Overrides
Remarks
The default value for this property is langword_csharp_True.
You should use this property if you need to create temporary model elements. These objects should not result in changes in the database. Therefore they are marked as non-persistent.
Note that you have to set this property to false immediately after object creation if you do not want it to be stored in the database. Changing the property value to false at a later point in time only prevents further changes to the object to be written to the database. However, changing the value to false does never remove anything from the database that has been written before!
If the PersistBehavior is set for a model entity, all depending properties and relations inherit the same persist behavior as their parent model entity.
PersistedProperties
Gets the collection of persisted properties of the dimension.
Declaration
public IEnumerable<PersistedProperty> PersistedProperties { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<PersistedProperty> |
Remarks
Similar to Properties; filtered for instances of type PersistedProperty and PersistBehavior.Full. This property is only used for the string templates building select statements.
PostSaveTriggers
Gets the post save trigger that are executed before an instance of the ModelEntityBase (EntityObject) is saved.
Declaration
public IEnumerable<Trigger> PostSaveTriggers { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Trigger> |
PreSaveTriggers
Gets the pre save trigger that are executed before an instance of the ModelEntityBase (EntityObject) is saved.
Declaration
public IEnumerable<Trigger> PreSaveTriggers { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Trigger> |
Properties
Gets the collection of properties.
Declaration
public ModelCollection<ModelProperty> Properties { get; }
Property Value
Type | Description |
---|---|
ModelCollection<ModelProperty> |
ReadOnlyExpression
Gets or sets a tcql expression that indicates if a instance of a model entity can be changed or not.
Declaration
public string ReadOnlyExpression { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
The TCQL expression must evaluate to true.
Relations
Gets the collection used to store the relations of the dimension to other dimensions.
Declaration
public ModelCollection<Relation> Relations { get; }
Property Value
Type | Description |
---|---|
ModelCollection<Relation> |
SyncBehavior
Gets or sets a value indicating whether a model entity is synced or not
Declaration
public SyncContent SyncBehavior { get; set; }
Property Value
Type | Description |
---|---|
SyncContent |
Triggers
Gets or sets the triggers defined on the current instance of ModelEntityBase
Declaration
public ModelCollection<Trigger> Triggers { get; set; }
Property Value
Type | Description |
---|---|
ModelCollection<Trigger> |
ValidationRules
Gets the collection of the validation of the dimension
Declaration
public ModelCollection<ValidationRule> ValidationRules { get; }
Property Value
Type | Description |
---|---|
ModelCollection<ValidationRule> |
Methods
Accept(ModelElementVisitor)
Accepts the visitor by dispatching the corresponding visit handler in the visitor for the given type.
Declaration
public override void Accept(ModelElementVisitor visitor)
Parameters
Type | Name | Description |
---|---|---|
ModelElementVisitor | visitor | the visitor to accept. |
Overrides
AddImplementedInterface(String)
Adds a type to the ImplementedInterfaces collection
Declaration
public void AddImplementedInterface(string typeName)
Parameters
Type | Name | Description |
---|---|---|
System.String | typeName | The assembly-qualified name of the type to add. See System.Type.AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace. |
Remarks
This is a helper method to make it easier to add interfaces by name (e.g. in scripts). Note that the
value of the PersistBehavior property of the ModelEntityBase
is copied to the
PersistBehavior property of the new ModelEntityInterface object.
Attach(ModelElement)
Attaches a dimension to a parent model element.
Declaration
protected override void Attach(ModelElement newParent)
Parameters
Type | Name | Description |
---|---|---|
ModelElement | newParent | Parent model element. |
Overrides
See Also
Attach(ModelElement, Boolean)
Attaches a dimension to a parent model element. This is only required if the datacontext of a model is created after some elements are added to the model. In this case first all entities have to be created, then the relations can be created.
Declaration
protected void Attach(ModelElement newParent, bool attachRelations)
Parameters
Type | Name | Description |
---|---|---|
ModelElement | newParent | Parent model element. |
System.Boolean | attachRelations | Indicates if relations of the entity should be attached. By default the relations should be attached immediatly. Only if the data context of a model is created after some elements are already added fist all entities have to be attached, then the relations can be attached. |
See Also
CreateAuditTrailMessage()
Creates the audit trail message for the current instance of ModelEntityBase. The method sets the EntityUuid, EntityName, OperationTimestamp.
Declaration
public EntityObject CreateAuditTrailMessage()
Returns
Type | Description |
---|---|
EntityObject | An instance of a AuditTrail EntityObject. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the current entity is not attached to an instance of Model. |
CreateAuditTrailMessage(String)
Creates the audit trail message for the current instance of ModelEntityBase. The method sets the EntityUuid, EntityName, OperationTimestamp and Username.
Declaration
public EntityObject CreateAuditTrailMessage(string username)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | The username of the use that has requested the audittrailmessage. |
Returns
Type | Description |
---|---|
EntityObject | An instance of a AuditTrail EntityObject. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown if the current entity is not attached to an instance of Model. |
CreateEntityObject<T>()
Creates a new instance of the EntityObject class that represents an object of this model entity.
Declaration
public T CreateEntityObject<T>()
where T : class
Returns
Type | Description |
---|---|
T | Newly created object. |
Type Parameters
Name | Description |
---|---|
T | EntityObject or one of the implemented interfaces (ImplementedInterfaces). |
Remarks
Note that the data context of the ModelEntityBase
object is copied as the data context
into the EntityObject object.
CreateEntityObject<T>(Boolean)
Creates a new instance of the EntityObject class that represents an object of this model entity.
Declaration
public T CreateEntityObject<T>(bool validateModelEntity)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | validateModelEntity | Indicates whether the model entity should be validated |
Returns
Type | Description |
---|---|
T | Newly created object. |
Type Parameters
Name | Description |
---|---|
T | EntityObject or one of the implemented interfaces (ImplementedInterfaces). |
Remarks
Note that the data context of the ModelEntityBase
object is copied as the data context
into the EntityObject object.
CreateEntityObject<T>(IEnumerable<KeyValuePair<Object, Object>>)
Creates a new instance of the EntityObject class that represents an object of this model entity.
Declaration
public T CreateEntityObject<T>(IEnumerable<KeyValuePair<object, object>> properties)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>> | properties | Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details). |
Returns
Type | Description |
---|---|
T | Newly created object |
Type Parameters
Name | Description |
---|---|
T | EntityObject or one of the implemented interfaces (ImplementedInterfaces). |
Remarks
The parameter properties
can be used to initialize the dynamic properties of the object. The collection contains
key/value pairs in which the key is the name of property. If you do not want to initialize properties you have to pass
null.
Note that the data context of the ModelEntityBase
object is copied as the data context
into the EntityObject object.
CreateEntityObject<T>(IEnumerable<KeyValuePair<Object, Object>>, Boolean)
Creates a new instance of the EntityObject class that represents an object of this model entity.
Declaration
public T CreateEntityObject<T>(IEnumerable<KeyValuePair<object, object>> properties, bool validateModelEntity)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>> | properties | Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details). |
System.Boolean | validateModelEntity | Indicates whether the model entity should be validated |
Returns
Type | Description |
---|---|
T | Newly created object |
Type Parameters
Name | Description |
---|---|
T | EntityObject or one of the implemented interfaces (ImplementedInterfaces). |
Remarks
The parameter properties
can be used to initialize the dynamic properties of the object. The collection contains
key/value pairs in which the key is the name of property. If you do not want to initialize properties you have to pass
null.
Note that the data context of the ModelEntityBase
object is copied as the data context
into the EntityObject object.
CreateEntityObject<T>(Guid, IEnumerable<KeyValuePair<Object, Object>>)
Creates a new instance of the EntityObject class that represents an object of this model entity.
Declaration
public T CreateEntityObject<T>(Guid objectUuid, IEnumerable<KeyValuePair<object, object>> properties)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Guid | objectUuid | Id of the object. System.Guid.Empty if it is a new object (see remarks section for details). |
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>> | properties | Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details). |
Returns
Type | Description |
---|---|
T | Newly created object |
Type Parameters
Name | Description |
---|---|
T | EntityObject or one of the implemented interfaces (ImplementedInterfaces). |
Remarks
If the entity object represents an existing object (e.g. coming from the database) pass its existing id
as objectUuid
. If it is a new entity object that has not existed before pass System.Guid.Empty.
In this case a new id will be generated for the object.
The parameter properties
can be used to initialize the dynamic properties of the object. The collection contains
key/value pairs in which the key is the name of property. If you do not want to initialize properties you have to pass
null.
Note that the data context of the ModelEntityBase
object is copied as the data context
into the EntityObject object.
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
See Also
CreateEntityObject<T>(Guid, IEnumerable<KeyValuePair<Object, Object>>, Boolean, Boolean, Boolean, Environment)
Creates a new instance of the EntityObject class that represents an object of this model entity.
Declaration
public T CreateEntityObject<T>(Guid objectUuid, IEnumerable<KeyValuePair<object, object>> properties, bool validateModelEntity, bool isClone = false, bool isDeserialization = false, Environment environment = null)
where T : class
Parameters
Type | Name | Description |
---|---|---|
System.Guid | objectUuid | Id of the object. System.Guid.Empty if it is a new object (see remarks section for details). |
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>> | properties | Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details). |
System.Boolean | validateModelEntity | Indicates whether the model entity should be validated |
System.Boolean | isClone | if set to |
System.Boolean | isDeserialization | if set to |
Environment | environment | "Optional" environment. |
Returns
Type | Description |
---|---|
T | Newly created object |
Type Parameters
Name | Description |
---|---|
T | EntityObject or one of the implemented interfaces (ImplementedInterfaces). |
Remarks
If the entity object represents an existing object (e.g. coming from the database) pass its existing id
as objectUuid
. If it is a new entity object that has not existed before pass System.Guid.Empty.
In this case a new id will be generated for the object.
The parameter properties
can be used to initialize the dynamic properties of the object. The collection contains
key/value pairs in which the key is the name of property. If you do not want to initialize properties you have to pass
null.
Note that the data context of the ModelEntityBase
object is copied as the data context
into the EntityObject object.
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
See Also
CreateEntityObject<T>(Environment)
Creates a new instance of the EntityObject class that represents an object of this model entity.
Declaration
public T CreateEntityObject<T>(Environment environment)
where T : class
Parameters
Type | Name | Description |
---|---|---|
Environment | environment | "Optional" environment. |
Returns
Type | Description |
---|---|
T | Newly created object. |
Type Parameters
Name | Description |
---|---|
T | EntityObject or one of the implemented interfaces (ImplementedInterfaces). |
Remarks
Note that the data context of the ModelEntityBase
object is copied as the data context
into the EntityObject object.
Evaluate<T>(String)
Evaluates the specified expression and returns a compiled function
Declaration
public T Evaluate<T>(string expression)
Parameters
Type | Name | Description |
---|---|---|
System.String | expression | The expression that should be compiled. |
Returns
Type | Description |
---|---|
T | The result of the expression when applied to the instance of the ModelEntityBase. |
Type Parameters
Name | Description |
---|---|
T | The datatype the result of the expression should be casted to |
Evaluate<T>(String, Environment, IEnumerable<QueryParameter>, EntityObject)
Evaluates the specified expression and returns a compiled function
Declaration
public T Evaluate<T>(string expression, Environment environment, IEnumerable<QueryParameter> parameters = null, EntityObject current = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | expression | The expression that should be compiled. |
Environment | environment | An instance of Environment that has to be supplied, if the expression referenes Environment variables |
System.Collections.Generic.IEnumerable<QueryParameter> | parameters | The parameters that are passed to the expression. |
EntityObject | current | Optional, current entity object. |
Returns
Type | Description |
---|---|
T | The result of the expression when applied to the instance of the ModelEntityBase. |
Type Parameters
Name | Description |
---|---|
T | The datatype the result of the expression should be casted to |
GetAutoIncludedRelations()
Iterates over validation rules, default value expressions, permissions and calculated properties and finds the relations that are contained in the various expressions.
Declaration
public List<string> GetAutoIncludedRelations()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.String> | A list of strings representing relation reference paths |
GetMember(String)
Gets a member dynamically.
Declaration
public override object GetMember(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the member to get. |
Returns
Type | Description |
---|---|
System.Object | Dynamic member. |
Overrides
NewInstance()
Creates a new instance of EntityObject basing the the current instance of ModelEntityBase
Declaration
public EntityObject NewInstance()
Returns
Type | Description |
---|---|
EntityObject | A new instance of EntityObject |
OnDeserializing(StreamingContext)
Called whenever deserialization of the model element is happening
Declaration
[OnDeserializing]
public void OnDeserializing(StreamingContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Runtime.Serialization.StreamingContext | context | Stream context used for deserialization. |
Remarks
This method is necessary to instantiate an instance of the current ModelElement after deserialization. As for the System.Runtime.Serialization.DataContractSerializer, constructors are not always called and fields not correctly initialized. While deserializing, this method is called and the fields of the ModelElement are correctly initialized.
RemoveImplementedInterface(String)
Removes a type from the ImplementedInterfaces collection
Declaration
public void RemoveImplementedInterface(string typeName)
Parameters
Type | Name | Description |
---|---|---|
System.String | typeName | The assembly-qualified name of the type to add. See System.Type.AssemblyQualifiedName. If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace. |
Remarks
This is a helper method to make it easier to remove interfaces by name (e.g. in scripts).
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Overrides
Validate(ref IList<PropertyValidationMessage>, Boolean)
Validates a ModelElement according to certain rules.
Declaration
protected override void Validate(ref IList<PropertyValidationMessage> messages, bool validateRecursively)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<PropertyValidationMessage> | messages | An list of strings that stores that picks up the validation errors of a model element. |
System.Boolean | validateRecursively | Indicates wheter to validate only the current model element or all its children (recursively) as well. |
Overrides
Remarks
The rules the ModelElement is validated against are dependent on the type of ModelElement that is validated. This method can be overridden to provide custom validation behavior for subclasses of ModelElement
When Validate(ref IList<PropertyValidationMessage>, Boolean) is called on a modelelement, the Validate(ref IList<PropertyValidationMessage>, Boolean) method of all children attatched to the modelelemnt are validated recursivly.