Class ModelEntityBase
- Namespace
- TimeCockpit.Data.DataModel
- Assembly
- TimeCockpit.Data.dll
Acts as the base class for entities in Time Cockpit's data model
public abstract class ModelEntityBase : ModelElement, IDynamicMetaObjectProvider, INotifyPropertyChanged, IDataErrorInfo
- Inheritance
-
ObjectModelEntityBase
- Implements
-
IDynamicMetaObjectProviderINotifyPropertyChangedIDataErrorInfo
- Derived
- Inherited Members
-
Object.Equals(Object)Object.Equals(Object, Object)Object.ReferenceEquals(Object, Object)Object.GetHashCode()Object.GetType()Object.MemberwiseClone()
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.
protected ModelEntityBase()
ModelEntityBase(IEnumerable<KeyValuePair<Object, Object>>)
Initializes a new instance of the ModelEntityBase class.
protected ModelEntityBase(IEnumerable<KeyValuePair<object, object>> properties)
Parameters
propertiesIEnumerable<KeyValuePair<Object, Object>>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.
protected ModelEntityBase(ModelEntityBase element)
Parameters
elementModelEntityBaseThe 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.
public CombinedModelCollectionView<RelationBase, Relation, LogicalRelation> AllRelations { get; }
Property Value
AuditMode
Gets or sets the audit mode for the given ModelEntityBase.
public AuditMode AuditMode { get; set; }
Property Value
CyclicRelations
Gets the cyclic relations.
public Relation[] CyclicRelations { get; }
Property Value
- Relation[]
DefaultDisplayPropertyName
Gets or sets the default property name to display
public string DefaultDisplayPropertyName { get; set; }
Property Value
- String
DefaultFormName
Gets or sets the default form of the ModelEntityBase.
public string DefaultFormName { get; set; }
Property Value
- String
The name of the default form.
DefaultListName
Gets or sets the default list of the ModelEntityBase.
public string DefaultListName { get; set; }
Property Value
- 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.
public string DefaultRelationListName { get; set; }
Property Value
- String
The default name of the relation list.
DependentModelEntities
Gets the dependent model entities in the correct order for deletion.
public IEnumerable<Dependency> DependentModelEntities { get; }
Property Value
- IEnumerable<Dependency>
DependentRelationPaths
Gets the dependent relation paths.
public IEnumerable<IEnumerable<Relation>> DependentRelationPaths { get; }
Property Value
- IEnumerable<IEnumerable<Relation>>
ImplementedInterfaces
Gets the collection used to store the interfaces implemented by this model entity
public ModelCollection<ModelEntityInterface> ImplementedInterfaces { get; }
Property Value
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
public bool IsDataSynced { get; }
Property Value
- Boolean
IsGenericRelationEntity
Gets or sets a value indicating whether this entity should act as a generic relation.
public bool IsGenericRelationEntity { get; set; }
Property Value
- 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
public bool IsModelSynced { get; }
Property Value
- Boolean
LogicalRelations
Gets the collection of logical relations.
public ModelCollection<LogicalRelation> LogicalRelations { get; }
Property Value
Permissions
Gets the read permissions of the ModelEntityBase
public ModelCollection<Permission> Permissions { get; }
Property Value
PersistBehavior
Gets or sets a value indicating whether the ModelElement instance should be persisted in
the database.
public override PersistBehavior PersistBehavior { get; set; }
Property Value
Remarks
The default value for this property is 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.
public IEnumerable<PersistedProperty> PersistedProperties { get; }
Property Value
- 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.
public IEnumerable<Trigger> PostSaveTriggers { get; }
Property Value
- IEnumerable<Trigger>
PreSaveTriggers
Gets the pre save trigger that are executed before an instance of the ModelEntityBase (EntityObject) is saved.
public IEnumerable<Trigger> PreSaveTriggers { get; }
Property Value
- IEnumerable<Trigger>
Properties
Gets the collection of properties.
public ModelCollection<ModelProperty> Properties { get; }
Property Value
ReadOnlyExpression
Gets or sets a tcql expression that indicates if a instance of a model entity can be changed or not.
public string ReadOnlyExpression { get; set; }
Property Value
- String
Remarks
The TCQL expression must evaluate to true.
Relations
Gets the collection used to store the relations of the dimension to other dimensions.
public ModelCollection<Relation> Relations { get; }
Property Value
SyncBehavior
Gets or sets a value indicating whether a model entity is synced or not
public SyncContent SyncBehavior { get; set; }
Property Value
Triggers
Gets or sets the triggers defined on the current instance of ModelEntityBase
public ModelCollection<Trigger> Triggers { get; set; }
Property Value
ValidationRules
Gets the collection of the validation of the dimension
public ModelCollection<ValidationRule> ValidationRules { get; }
Property Value
Methods
Accept(ModelElementVisitor)
Accepts the visitor by dispatching the corresponding visit handler in the visitor for the given type.
public override void Accept(ModelElementVisitor visitor)
Parameters
visitorModelElementVisitorthe visitor to accept.
AddImplementedInterface(String)
Adds a type to the ImplementedInterfaces collection
public void AddImplementedInterface(string typeName)
Parameters
typeNameStringThe 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.
protected override void Attach(ModelElement newParent)
Parameters
newParentModelElementParent model element.
- 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.
protected void Attach(ModelElement newParent, bool attachRelations)
Parameters
newParentModelElementParent model element.
attachRelationsBooleanIndicates 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.
public EntityObject CreateAuditTrailMessage()
Returns
- EntityObject
An instance of a AuditTrail EntityObject.
Exceptions
- 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.
public EntityObject CreateAuditTrailMessage(string username)
Parameters
usernameStringThe username of the use that has requested the audittrailmessage.
Returns
- EntityObject
An instance of a AuditTrail EntityObject.
Exceptions
- 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.
public T CreateEntityObject<T>()
where T : class
Returns
- T
Newly created object.
Type Parameters
TEntityObject 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.
public T CreateEntityObject<T>(bool validateModelEntity)
where T : class
Parameters
validateModelEntityBooleanIndicates whether the model entity should be validated
Returns
- T
Newly created object.
Type Parameters
TEntityObject 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.
public T CreateEntityObject<T>(IEnumerable<KeyValuePair<object, object>> properties)
where T : class
Parameters
propertiesIEnumerable<KeyValuePair<Object, Object>>Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details).
Returns
- T
Newly created object
Type Parameters
TEntityObject 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.
public T CreateEntityObject<T>(IEnumerable<KeyValuePair<object, object>> properties, bool validateModelEntity)
where T : class
Parameters
propertiesIEnumerable<KeyValuePair<Object, Object>>Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details).
validateModelEntityBooleanIndicates whether the model entity should be validated
Returns
- T
Newly created object
Type Parameters
TEntityObject 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.
public T CreateEntityObject<T>(Guid objectUuid, IEnumerable<KeyValuePair<object, object>> properties)
where T : class
Parameters
objectUuidGuidId of the object. System.Guid.Empty if it is a new object (see remarks section for details).
propertiesIEnumerable<KeyValuePair<Object, Object>>Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details).
Returns
- T
Newly created object
Type Parameters
TEntityObject 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
- System.ArgumentException
Tis not EntityObject and not in the list of implemented interfaces (ImplementedInterfaces)
- 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.
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
objectUuidGuidId of the object. System.Guid.Empty if it is a new object (see remarks section for details).
propertiesIEnumerable<KeyValuePair<Object, Object>>Collection of dynamic properties used to initialize the object. null if no initialization is needed (see remarks section for details).
validateModelEntityBooleanIndicates whether the model entity should be validated
isCloneBooleanif set to
truethe method is called in the process of cloning an EntityObject.isDeserializationBooleanif set to
truethe method is called in the process of deserializing an EntityObject.environmentEnvironment"Optional" environment.
Returns
- T
Newly created object
Type Parameters
TEntityObject 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
- System.ArgumentException
Tis not EntityObject and not in the list of implemented interfaces (ImplementedInterfaces)
- See Also
CreateEntityObject<T>(Environment)
Creates a new instance of the EntityObject class that represents an object of this model entity.
public T CreateEntityObject<T>(Environment environment)
where T : class
Parameters
environmentEnvironment"Optional" environment.
Returns
- T
Newly created object.
Type Parameters
TEntityObject 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
public T Evaluate<T>(string expression)
Parameters
expressionStringThe expression that should be compiled.
Returns
- T
The result of the expression when applied to the instance of the ModelEntityBase.
Type Parameters
TThe 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
public T Evaluate<T>(string expression, Environment environment, IEnumerable<QueryParameter> parameters = null, EntityObject current = null)
Parameters
expressionStringThe expression that should be compiled.
environmentEnvironmentAn instance of Environment that has to be supplied, if the expression referenes Environment variables
parametersIEnumerable<QueryParameter>The parameters that are passed to the expression.
currentEntityObjectOptional, current entity object.
Returns
- T
The result of the expression when applied to the instance of the ModelEntityBase.
Type Parameters
TThe 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.
public List<string> GetAutoIncludedRelations()
Returns
- List<String>
A list of strings representing relation reference paths
GetMember(String)
Gets a member dynamically.
public override object GetMember(string name)
Parameters
nameStringName of the member to get.
Returns
- Object
Dynamic member.
NewInstance()
Creates a new instance of EntityObject basing the the current instance of ModelEntityBase
public EntityObject NewInstance()
Returns
- EntityObject
A new instance of EntityObject
OnDeserializing(StreamingContext)
Called whenever deserialization of the model element is happening
[OnDeserializing]
public void OnDeserializing(StreamingContext context)
Parameters
contextStreamingContextStream 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
public void RemoveImplementedInterface(string typeName)
Parameters
typeNameStringThe 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.
public override string ToString()
Returns
- String
A System.String that represents this instance.
Validate(ref IList<PropertyValidationMessage>, Boolean)
Validates a ModelElement according to certain rules.
protected override void Validate(ref IList<PropertyValidationMessage> messages, bool validateRecursively)
Parameters
messagesIList<PropertyValidationMessage>An list of strings that stores that picks up the validation errors of a model element.
validateRecursivelyBooleanIndicates wheter to validate only the current model element or all its children (recursively) as well.
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.