Search Results for

    Show / Hide Table of Contents

    Class EntityObject

    Represents an instance of a ModelEntityBase.

    Inheritance
    System.Object
    DynamicObject
    EntityObject
    Implements
    System.Dynamic.IDynamicMetaObjectProvider
    System.ComponentModel.INotifyPropertyChanged
    IEntityObject
    System.IComparable
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: TimeCockpit.Data
    Assembly: TimeCockpit.Data.dll
    Syntax
    public class EntityObject : DynamicObject, IDynamicMetaObjectProvider, INotifyPropertyChanged, IEntityObject, IComparable

    Constructors

    EntityObject()

    Initializes a new instance of the EntityObject class.

    Declaration
    public EntityObject()

    Properties

    CreationVersion

    Gets the creation version of the EntityObject

    Declaration
    public ulong CreationVersion { get; }
    Property Value
    Type Description
    System.UInt64

    Entity

    Gets or sets the ModelEntityBase of the object.

    Declaration
    public ModelEntityBase Entity { get; protected set; }
    Property Value
    Type Description
    ModelEntityBase

    IsChanged

    Gets a value indicating whether the object was changed. See also OnPropertyChanged(String, Object, Object).

    Declaration
    public bool IsChanged { get; }
    Property Value
    Type Description
    System.Boolean

    IsCloned

    Gets a value indicating whether this instance is cloned.

    Declaration
    public bool IsCloned { get; }
    Property Value
    Type Description
    System.Boolean

    IsDeleted

    Gets a value indicating whether the object was deleted. See also OnPropertyChanged(String, Object, Object).

    Declaration
    public bool IsDeleted { get; }
    Property Value
    Type Description
    System.Boolean

    IsNew

    Gets a value indicating whether the object is new. See also OnPropertyChanged(String, Object, Object).

    Declaration
    public bool IsNew { get; }
    Property Value
    Type Description
    System.Boolean

    IsReadOnly

    Gets a value indicating whether an EntityObject is locked depending on the TimeCockpit.Data.DataModel.ModelEntityBase.ReadOnlyFunction.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    If the ModelEntityBase that underlies the current EntityObject has no ReadOnlyExpression set the property always returns false. If the ModelEntityBase has a ReadOnlyExpression set, it is evaluated with the values of the current EntityObject an returns a boolean value accordingly.

    Item[String]

    Gets the value of a specified member

    Declaration
    public object this[string propertyName] { get; set; }
    Parameters
    Type Name Description
    System.String propertyName

    The name of the member to get the value for.

    Property Value
    Type Description
    System.Object

    Returns the value of the specified member.

    Remarks

    Internally, this indexer calls GetMember(String) and SetMember(String, Object). The indexer was introduced for the use in IronPython, where no GetMember(String) or SetMember(String, Object) can be called. Without the indexer it was not possible in Python to run through the properties/ relations of a ModelEntityBase and set the values of a dependent EntityObject.

    LastUpdateVersion

    Gets the update version of the EntityObject

    Declaration
    public ulong LastUpdateVersion { get; }
    Property Value
    Type Description
    System.UInt64

    LocalizedPropertyValues

    Gets the localized property values.

    Declaration
    public LocalizedTextPropertyCollection LocalizedPropertyValues { get; }
    Property Value
    Type Description
    LocalizedTextPropertyCollection

    Me

    Gets the it self

    Declaration
    public EntityObject Me { get; }
    Property Value
    Type Description
    EntityObject
    Remarks

    This property is needed for DataBinding reasons. Whenever a property of an EntityObject is changed (e.g. via z.SetMember("X", "Y")), the OnPropertyChanged(String, Object, Object) event of that property + the OnPropertyChanged(String, Object, Object) event of the Me property is fired.

    ModelEntityName

    Gets the name of the current instance of EntityObject

    Declaration
    public string ModelEntityName { get; }
    Property Value
    Type Description
    System.String
    Implements
    IEntityObject.ModelEntityName

    ObjectUuid

    Gets the unique id of the object.

    Declaration
    public Guid ObjectUuid { get; }
    Property Value
    Type Description
    System.Guid
    Implements
    IEntityObject.ObjectUuid

    Permission

    Gets the permissions of an EntityObject

    Declaration
    public PermissionType Permission { get; }
    Property Value
    Type Description
    PermissionType

    RelationIdentifiers

    Gets the relation identifiers for the EntityObject

    Declaration
    public RelationIdentifiers RelationIdentifiers { get; }
    Property Value
    Type Description
    RelationIdentifiers

    States

    Gets a dictionary of property states for an object.

    Declaration
    protected MemberStatus[] States { get; }
    Property Value
    Type Description
    MemberStatus[]

    Values

    Gets a dictionary of values for an object.

    Declaration
    protected object[] Values { get; }
    Property Value
    Type Description
    System.Object[]

    Methods

    CalculateMember(String)

    Evaluates a formla, applies it to this EntityObject and returns the result.

    Declaration
    public object CalculateMember(string formula)
    Parameters
    Type Name Description
    System.String formula

    Formla to evaluate

    Returns
    Type Description
    System.Object

    Result of the formula

    Exceptions
    Type Condition
    System.NullReferenceException

    might throw a NullReferenceException.

    See Also
    CalculatedProperty

    Clone()

    Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

    Declaration
    public EntityObject Clone()
    Returns
    Type Description
    EntityObject

    A cloned entity object

    Clone(Boolean)

    Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

    Declaration
    public EntityObject Clone(bool deepClone)
    Parameters
    Type Name Description
    System.Boolean deepClone

    if set to true the instances of EntityObject are created with a new id.

    Returns
    Type Description
    EntityObject

    A cloned entity object

    Clone(Boolean, Boolean)

    Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

    Declaration
    public EntityObject Clone(bool deepClone, bool resetMembersInReadonlyExpression)
    Parameters
    Type Name Description
    System.Boolean deepClone

    if set to true the instances of EntityObject are created with a new id.

    System.Boolean resetMembersInReadonlyExpression

    if set to true [reset members in readonly expression].

    Returns
    Type Description
    EntityObject

    A cloned entity object

    Clone(Boolean, Boolean, Environment)

    Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

    Declaration
    public EntityObject Clone(bool deepClone, bool resetMembersInReadonlyExpression, Environment environment)
    Parameters
    Type Name Description
    System.Boolean deepClone

    if set to true the instances of EntityObject are created with a new id.

    System.Boolean resetMembersInReadonlyExpression

    if set to true [reset members in readonly expression].

    Environment environment

    An instance of environment to perform permission validation.

    Returns
    Type Description
    EntityObject

    A cloned entity object

    Clone(ModelEntityBase)

    Makes a deep clone of an EntityObject but does not preserve the orignial ModelEntityBase.

    Declaration
    public EntityObject Clone(ModelEntityBase entity)
    Parameters
    Type Name Description
    ModelEntityBase entity

    The ModelEntityBase that the cloned EntityObject should base on.

    Returns
    Type Description
    EntityObject

    A cloned instance of an EntityObject.

    CompareTo(Object)

    Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

    Declaration
    public int CompareTo(object obj)
    Parameters
    Type Name Description
    System.Object obj

    An object to compare with this instance.

    Returns
    Type Description
    System.Int32

    A value that indicates the relative order of the objects being compared.

    Implements
    System.IComparable.CompareTo(System.Object)

    CopyTo(EntityObject)

    Copies the values of an instance of an EntityObject to another instance. This method only copies first level relations and properties. ///

    Declaration
    public void CopyTo(EntityObject target)
    Parameters
    Type Name Description
    EntityObject target

    The target EntityObject.

    Deserialize(String, EntityObject, Model)

    Deserializes an EntityObject from a string in XML format.

    Declaration
    public static EntityObject Deserialize(string data, EntityObject parentEntity, Model model)
    Parameters
    Type Name Description
    System.String data

    An instance of EntityObject in XML representation.

    EntityObject parentEntity

    The parent EntityObject

    Model model

    An instance of Model to fetch type information about the EntityObject's underlying ModelEntityBase.

    Returns
    Type Description
    EntityObject

    An instance of EntityObject deserialized from XML

    Deserialize(XElement, EntityObject, Model)

    Deserializes an EntityObject from a string in XML format.

    Declaration
    public static EntityObject Deserialize(XElement root, EntityObject parentEntity, Model model)
    Parameters
    Type Name Description
    System.Xml.Linq.XElement root

    System.Xml.Linq.XElement from the XML parser

    EntityObject parentEntity

    The parent EntityObject

    Model model

    An instance of Model

    Returns
    Type Description
    EntityObject

    The deserialized instance of EntityObject

    Remarks

    For EntityObject that have relations, this method calls itself recursively to deserialize all the properties/ relations of an EntityObject. See also Serialize().

    Exceptions
    Type Condition
    UnknownEncodingException

    If the propertyEncoding attribute is present in the XML to deserialize and it is set to another value than 'Base64' this method throws a UnknownEncodingException.

    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 EntityObject.

    Type Parameters
    Name Description
    T

    The datatype the result of the expression should be casted to

    Evaluate<T>(String, Environment, IEnumerable<QueryParameter>)

    Evaluates the specified expression and returns a compiled function

    Declaration
    public T Evaluate<T>(string expression, Environment environment, IEnumerable<QueryParameter> parameters = 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.

    Returns
    Type Description
    T

    The result of the expression when applied to the instance of the EntityObject.

    Type Parameters
    Name Description
    T

    The datatype the result of the expression should be casted to

    GetActualMember(String)

    Gets the actual value of the specified member.

    Declaration
    public virtual object GetActualMember(string name)
    Parameters
    Type Name Description
    System.String name

    Name of the member.

    Returns
    Type Description
    System.Object

    Returns the actual value of the specified member. The default implementation of this method calls GetMember(String). However, classes that implement specific business logic in GetMember(String) that should be available from scripts but should NOT be used for saving objects' values to the database can override GetActualMember.

    GetChangedMembers()

    Gets a list of member names that have the status Changed

    Declaration
    public IEnumerable<string> GetChangedMembers()
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<System.String>

    A list of member name that have the status Changed

    GetMember(Int32)

    Gets the value of the specified member.

    Declaration
    public object GetMember(int index)
    Parameters
    Type Name Description
    System.Int32 index

    Index of the member.

    Returns
    Type Description
    System.Object

    Returns the value of the specified member.

    GetMember(String)

    Gets the value of the specified member.

    Declaration
    public override object GetMember(string name)
    Parameters
    Type Name Description
    System.String name

    Name of the member.

    Returns
    Type Description
    System.Object

    Returns the value of the specified member.

    Overrides
    DynamicObject.GetMember(String)
    Remarks

    This method also returns the clr properties '{ModelEntityName}Uuid' and 'IsReadOnly' of an EntityObject.

    GetMembersByState(MemberStatus)

    Gets a list of member names that have the requested state.

    Declaration
    public IEnumerable<string> GetMembersByState(MemberStatus state)
    Parameters
    Type Name Description
    MemberStatus state

    Reqested state.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<System.String>

    A list of member name that have the requested state.

    GetMetaObject(Expression)

    Gets the meta object of the dynamic object.

    Declaration
    public override DynamicMetaObject GetMetaObject(Expression parameter)
    Parameters
    Type Name Description
    System.Linq.Expressions.Expression parameter

    Provided by the DLR (Dynamic Language Runtime).

    Returns
    Type Description
    System.Dynamic.DynamicMetaObject

    System.Dynamic.DynamicMetaObject that represents this specific object’s binding logic.

    Overrides
    DynamicObject.GetMetaObject(Expression)

    GetPropertyIndex(String)

    Gets ContentMap index for a name.

    Declaration
    protected virtual int GetPropertyIndex(string name)
    Parameters
    Type Name Description
    System.String name

    Name of the property to get ContentMap index for.

    Returns
    Type Description
    System.Int32

    The ContentMap index of the Prooperty. Value is -1 if property does not exists in ContentMap

    GetValidationMessages(NameLocalizer)

    Gets the validation messages.

    Declaration
    public IEnumerable<ValidationMessage> GetValidationMessages(NameLocalizer localizer)
    Parameters
    Type Name Description
    NameLocalizer localizer

    The localizer to use for localizing validation rules.

    Returns
    Type Description
    System.Collections.Generic.IEnumerable<ValidationMessage>

    Iterates the validation messages.

    HasPermission(String, PermissionType)

    Checks if a user has a permission of a certain type.

    Declaration
    public bool HasPermission(string memberName, PermissionType permissionType)
    Parameters
    Type Name Description
    System.String memberName

    The name of the property to check for permission.

    PermissionType permissionType

    The type of the permission (see also PermissionType)

    Returns
    Type Description
    System.Boolean

    True, if the property has the same permission as permissionIdentifier, else false.

    MarkAsDeleted()

    Marks the object as deleted.

    Declaration
    public void MarkAsDeleted()

    MarkAsNew(Boolean)

    Marks an entity object as new

    Declaration
    public void MarkAsNew(bool resetMemberStates = true)
    Parameters
    Type Name Description
    System.Boolean resetMemberStates

    Indicates whether the member states and IssChanged should be adjusted.

    OnPropertyChanged(Int32, Object, Object)

    Invoked whenever the value of any property on this object has been updated. The specific property that changed is reported in the event data.

    Declaration
    protected virtual void OnPropertyChanged(int index, object previousValue, object currentValue)
    Parameters
    Type Name Description
    System.Int32 index

    Index of the property that has been updated.

    System.Object previousValue

    the previous value of the property.

    System.Object currentValue

    the currentValue of the property.

    Remarks

    This method sets a property in the Values collection of an EntityObject to MemberStatus.Changed. Each call of the method calls OnPropertyChanged for the clr properties 'IsNew', 'IsChanged', 'Me', 'IsReadonly'.

    OnPropertyChanged(String, Object, Object)

    Invoked whenever the value of any property on this object has been updated. The specific property that changed is reported in the event data.

    Declaration
    protected virtual void OnPropertyChanged(string propertyName, object previousValue, object currentValue)
    Parameters
    Type Name Description
    System.String propertyName

    Name of the property that has been updated.

    System.Object previousValue

    the previous value of the property.

    System.Object currentValue

    the current value of the property.

    Remarks

    This method sets a property in the Values collection of an EntityObject to MemberStatus.Changed. Each call of the method calls OnPropertyChanged for the clr properties 'Me', 'IsReadonly'.

    Serialize()

    Serializes an EntityObject in XML

    Declaration
    public XmlReader Serialize()
    Returns
    Type Description
    System.Xml.XmlReader

    An instance of an System.Xml.XmlReader representing the serialized EntityObject.

    Serialize(Boolean)

    Serializes an EntityObject in XML.

    Declaration
    public XmlReader Serialize(bool idsOnly)
    Parameters
    Type Name Description
    System.Boolean idsOnly

    Determines whether to serialize the whole entity object in case of a relation or just the identifier or the relation.

    Returns
    Type Description
    System.Xml.XmlReader

    An instance of an System.Xml.XmlReader representig EntityObject.

    Remarks

    If the EntityObject that should be serialized has not been attatched to an instance of Model the method serializes the type information of the underlying ModelEntityBase as well. During deserialization (see Deserialize(String, EntityObject, Model)) the ModelEntityBase type is reconstructed and the EntityObject can be deserialized on its basis.

    This method serializes an EntityObject in UTF8 XML

    This method serializes properties of a EntityObject by converting their value into a Base64 string. Therefore, e.g. a TextProperty can contain all ASCII character. If the values would not be encoded, control characters e.g. would lead to invalid XML.

    Serialize(XmlWriter, Boolean)

    Writes the XML representation of an EntityObject to a predifined instance of System.Xml.XmlWriter.

    Declaration
    public void Serialize(XmlWriter xmlWriter, bool idsOnly)
    Parameters
    Type Name Description
    System.Xml.XmlWriter xmlWriter

    The System.Xml.XmlWriter to write to.

    System.Boolean idsOnly

    Determines whether to serialize the whole EntityObject in case of a relation or just the identifier of the relations.

    Remarks

    If the EntityObject that should be serialized has not been attatched to an instance of Model the method serializes the type information of the underlying ModelEntityBase as well. During deserialization (see Deserialize(String, EntityObject, Model)) the ModelEntityBase type is reconstructed and the EntityObject can be deserialized on its basis.

    This method serializes an EntityObject in UTF8 XML

    This method serializes properties of a EntityObject by converting their value into a Base64 string. Therefore, e.g. a TextProperty can contain all ASCII character. If the values would not be encoded, control characters e.g. would lead to invalid XML.

    SetMember(Int32, Object)

    Sets a dynamic member.

    Declaration
    public void SetMember(int index, object value)
    Parameters
    Type Name Description
    System.Int32 index

    Index of the member to set.

    System.Object value

    Value to set.

    SetMember(String, Object)

    Sets a dynamic member.

    Declaration
    public override void SetMember(string name, object value)
    Parameters
    Type Name Description
    System.String name

    Name of the member to set.

    System.Object value

    Value to set.

    Overrides
    DynamicObject.SetMember(String, Object)

    SetMember(String, Object, Boolean, Boolean)

    Sets a dynamic member.

    Declaration
    public void SetMember(string name, object value, bool initialization, bool ignoreDefaultValues = false)
    Parameters
    Type Name Description
    System.String name

    Name of the member to set.

    System.Object value

    Value to set.

    System.Boolean initialization

    Indicates if SetMember is called during initialization of the object.

    System.Boolean ignoreDefaultValues

    Indicates that no default values are set if this flag is set to true. Default is false

    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
    System.Object.ToString()
    Remarks

    This methods returns the value of the default display property as string. If the default display property happens to be a relation, it returns the value of the default display property of the EntityObject that is behind the relation.

    Validate(out List<String>, out List<ValidationRule>, NameLocalizer)

    Validates all values (properties and relations) of an instance of an EntityObject

    Declaration
    public bool Validate(out List<string> errorMessages, out List<ValidationRule> failingValidationRules, NameLocalizer localizer)
    Parameters
    Type Name Description
    System.Collections.Generic.List<System.String> errorMessages

    The error messages provided by the failing ValidationRules.

    System.Collections.Generic.List<ValidationRule> failingValidationRules

    The ValidationRules that raised the validation error

    NameLocalizer localizer

    The NameLocalizer used to get the correct localizations for properties and validation rules.

    Returns
    Type Description
    System.Boolean

    True if the EntityObject validates o.k, else false

    Remarks

    Internally, this method calls Validate(String, out String, out ValidationRule, NameLocalizer)

    Validate(String, out String, out ValidationRule, NameLocalizer)

    Validates a property of an instance of EntityObject in accordance to the ValidationRules defined in the underlying ModelEntityBase.

    Declaration
    public bool Validate(string name, out string message, out ValidationRule failingValidationRule, NameLocalizer localizer)
    Parameters
    Type Name Description
    System.String name

    The name of the property that is to be validated.

    System.String message

    An error message provided by the failing ValidationRule.

    ValidationRule failingValidationRule

    The ValidationRule that raised the validation error.

    NameLocalizer localizer

    The NameLocalizer used to get the correct localizations for properties and validation rules.

    Returns
    Type Description
    System.Boolean

    True if the EntityObject validates o.k, else false.

    Exceptions
    Type Condition
    System.NullReferenceException

    This method throws a System.NullReferenceException if a ValidationRule contains a condition that contains a reference to a relation which is null. :Iif(Current.Project.ProjectUuid = Current.Task.Project.ProjectUuid, True, False) If 'Project' in Current.Task.Project is null, the latter example throws a System.NullReferenceException. This is because up to now nullable/notnullable relations do no exists (NOT YET).

    Events

    PropertyChanged

    Occurs after the value of an application settings property is changed.

    Declaration
    public event PropertyChangedEventHandler PropertyChanged
    Event Type
    Type Description
    System.ComponentModel.PropertyChangedEventHandler

    Extension Methods

    EntityObjectExtensions.SetTextMemberTruncated(EntityObject, String, String)
    In This Article
    Back to top Copyright © 2020 software architects gmbh