Search Results for

    Show / Hide Table of Contents

    Class BaseEntity

    The base class that every system implementation of IBaseEntity inherits from

    Inheritance
    System.Object
    BaseEntity
    BaseEntityWithPermissions
    Implements
    IBaseEntity
    System.IEquatable<IBaseEntity>
    ICanTrackProperties
    System.ComponentModel.INotifyPropertyChanging
    System.ComponentModel.INotifyPropertyChanged
    ICloneableAsync
    Inherited Members
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: LemonEdge.API.Core
    Assembly: API.dll
    Syntax
    [DataContract]
    public abstract class BaseEntity : IBaseEntity, IEquatable<IBaseEntity>, ICanTrackProperties, INotifyPropertyChanging, INotifyPropertyChanged, ICloneableAsync
    Remarks

    If using our auto-code designers, or other tools the system will always create entities for you that inherit this base class. These correctly implement all the LemonEdge technology such as the following interfaces:

    • entityUpdateContext: Holds an instance of IEntityUpdater
    • IBaseEntity: The base entity interface implementation
    • System.ComponentModel.INotifyPropertyChanging: Ensures all property changes are correctly raised to listeners
    • System.ComponentModel.INotifyPropertyChanged: Ensures all property changes are correctly raised to listeners
    • ICloneableAsync: Ensures this entity can be cloned, and have all its property values copied

    You are however free to completely implement your own base class as long as it implements all the required interfaces

    Fields

    HISTORY_ENDROWUPDATE_COLNAME

    The name reserved by the system for the column holding change dates for the auditing table

    For every entity in the system that has a table created in the database, it also has an associated audit table

    Declaration
    public const string HISTORY_ENDROWUPDATE_COLNAME = "EndUpdated"
    Field Value
    Type Description
    System.String

    Properties

    AccountID

    LemonEdge is a multi-tenanted system, and thus you can have several different accounts all residing in the same database

    The default root account is 1

    This property holds the account the item belongs to. It can not be modified by a user, it is maintained internally by the system

    Declaration
    public long AccountID { get; set; }
    Property Value
    Type Description
    System.Int64

    CanvasID

    If this record is within a canvas, this holds the canvas id for the record.

    By ensuring all items in the system have a canvas property, we can guarantee a mechanism for isolating canvases and ensuring all entities are compatabile with them

    Declaration
    public Guid? CanvasID { get; set; }
    Property Value
    Type Description
    System.Nullable<System.Guid>

    CanvasID_Label

    If this record is within a canvas, this holds the canvas label for the record

    Declaration
    public string CanvasID_Label { get; set; }
    Property Value
    Type Description
    System.String

    ID

    All items in the system have a globally unique id.

    This is used instead of auto-increment numbers for several reasons, but the main one being it enables all entities to be designed to cope with importing/exporting/copying. It is very easy to create an entire copy of an account into another one by maintaining the same ids

    Declaration
    public Guid ID { get; set; }
    Property Value
    Type Description
    System.Guid

    LastUpdated

    The server datetime stamps of when this item was last udpated in the system

    By ensuring every record has a datetimestamp for changes, and by keeping all old records, we can ensure the entire system can be ran as of any point in time in the past

    Declaration
    public DateTimeOffset LastUpdated { get; set; }
    Property Value
    Type Description
    System.DateTimeOffset
    Remarks

    We should always use datetimeoffsets. They are international, with time zones, but most importantly odata supports them and not datetime

    ModifiedByUserID

    This holds the id of the user that made the change to the item

    Declaration
    public Guid ModifiedByUserID { get; set; }
    Property Value
    Type Description
    System.Guid

    ModifiedByUserID_Label

    This holds the name of the user that made the change to the item

    Declaration
    public string ModifiedByUserID_Label { get; set; }
    Property Value
    Type Description
    System.String

    TrackChanges

    By default, no changes are tracked. Only services directly connecting to the db should track property changes.

    Declaration
    public static bool TrackChanges { get; set; }
    Property Value
    Type Description
    System.Boolean

    Methods

    AddTrackedOriginalValue(String, Object)

    Should be called whenever a tracked property has its value changed. This ensures the original value is tracked along with the fact it has changed.

    Declaration
    protected void AddTrackedOriginalValue(string propName, object value)
    Parameters
    Type Name Description
    System.String propName
    System.Object value

    ClearTrackedOriginalValues()

    Clears all records of the tracked changes against this entity.

    Note: It does *not* reset any changed values back to their original values (ResetChangedTrackedPropertiesToOriginalValues() does that), it simply clears the tracking of those changes

    Declaration
    public void ClearTrackedOriginalValues()

    Clone(Object)

    ICloneableAsync implementation - Creates a new instance of this class with all the same property values as this instance

    Declaration
    public Task<object> Clone(object context)
    Parameters
    Type Name Description
    System.Object context

    A context item used for creating a new instance of this item. Can allow permission checks and other functionality.

    Returns
    Type Description
    System.Threading.Tasks.Task<System.Object>

    A task that creates new instance of this class with all the same property values as this instance

    CopyFromEntity(IBaseEntity)

    Declaration
    protected virtual void CopyFromEntity(IBaseEntity source)
    Parameters
    Type Name Description
    IBaseEntity source

    CopyFromSource(Object)

    ICloneableAsync implementation - Updates all properties in this item to have the same properties as the source object.

    The source object should be of the same type as this one

    Declaration
    public void CopyFromSource(object source)
    Parameters
    Type Name Description
    System.Object source

    The source object to copy all values from. Should be of the same type as this one.

    Equals(IBaseEntity)

    IEquatable implementation of Equals, evaluating if the ID matches

    Declaration
    public virtual bool Equals(IBaseEntity other)
    Parameters
    Type Name Description
    IBaseEntity other

    The other IBaseEntity to compare on IDs

    Returns
    Type Description
    System.Boolean

    True if the IDs match

    Equals(Object)

    IEquatable implementation of Equals, evaluating if the ID matches

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj

    The other IBaseEntity to compare on IDs

    Returns
    Type Description
    System.Boolean

    True if the IDs match

    Overrides
    System.Object.Equals(System.Object)

    GetAllOriginalTrackedPropertyValues()

    For all properties that are marked to track values (indicated with DBTrackChangesAttribute), this returns the a dictionary of property name and associated original unchanged value for properties that have had their value changed

    Declaration
    public IReadOnlyDictionary<string, object> GetAllOriginalTrackedPropertyValues()
    Returns
    Type Description
    System.Collections.Generic.IReadOnlyDictionary<System.String, System.Object>

    A dictionary of property name and associated original value for properties that have had their value changed

    GetHashCode()

    Returns a hashcode for this entity based on the ID

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32

    A hashcode for this entity based on the ID

    Overrides
    System.Object.GetHashCode()

    GetLabel(String)

    For properties that are Guid properties holding a relationship to another entity, this function returns the label held for that id

    This is done by the class that implements this interface holding a xxx_Label property for every xxx Guid relationship property with a label

    Declaration
    public string GetLabel(string propName)
    Parameters
    Type Name Description
    System.String propName

    The Guid relationship property name to return the label for that item of

    Returns
    Type Description
    System.String

    The label held for the specified guid relationship property

    HasTrackedPropertyChanged(String)

    Indicates if a tracked property (indicated with DBTrackChangesAttribute) has had its value changed

    Declaration
    public bool HasTrackedPropertyChanged(string propName)
    Parameters
    Type Name Description
    System.String propName

    The name of the property to check if its value has changed

    Returns
    Type Description
    System.Boolean

    True if a tracked property (indicated with DBTrackChangesAttribute) has had its value changed

    IsBasePropertyName(String)

    Returns true if the specified property name is one of the core base properties specified in IBaseEntity

    Declaration
    public static bool IsBasePropertyName(string name)
    Parameters
    Type Name Description
    System.String name

    The name of the property on an entity

    Returns
    Type Description
    System.Boolean

    True if the specified property name is one of the core base properties specified in IBaseEntity

    IsBaseRelationshipID(String)

    Returns true if the specified property is one of the core base properties specified in IBaseEntity that is a relationship property

    Declaration
    public static bool IsBaseRelationshipID(string name)
    Parameters
    Type Name Description
    System.String name

    The name of the property on an entity

    Returns
    Type Description
    System.Boolean

    True if the specified property is one of the core base properties specified in IBaseEntity that is a relationship property

    OnPropertyChanged(String)

    Notifies any System.ComponentModel.INotifyPropertyChanged listeners

    Declaration
    protected virtual void OnPropertyChanged(string propName)
    Parameters
    Type Name Description
    System.String propName

    The property that is changing its value

    OnPropertyChanging(String)

    Notifies any System.ComponentModel.INotifyPropertyChanging listeners

    Declaration
    protected void OnPropertyChanging(string propName)
    Parameters
    Type Name Description
    System.String propName

    The property that is changing its value

    OriginalTrackedPropertyValue(String)

    Returns the original value of a property that has its value tracked (indicated with DBTrackChangesAttribute) before any changes

    Declaration
    public object OriginalTrackedPropertyValue(string propName)
    Parameters
    Type Name Description
    System.String propName

    The name of the property to return the original value for

    Returns
    Type Description
    System.Object

    The original value of a property that has its value tracked (indicated with DBTrackChangesAttribute) before any changes

    Remarks

    Will throw an error if the property has not changed value and still has its original value

    OriginalTrackedPropertyValue<T>(String)

    Returns the original value of a property that has its value tracked (indicated with DBTrackChangesAttribute) before any changes

    Declaration
    public T OriginalTrackedPropertyValue<T>(string propName)
    Parameters
    Type Name Description
    System.String propName

    The name of the property to return the original value for

    Returns
    Type Description
    T

    The original value of a property that has its value tracked (indicated with DBTrackChangesAttribute) before any changes

    Type Parameters
    Name Description
    T

    The type to return the property value as. Should match the actual type of the property.

    Remarks

    Will throw an error if the property has not changed value and still has its original value

    ResetChangedTrackedPropertiesToOriginalValues()

    For each tracked property (indicated with DBTrackChangesAttribute) that has had its value changed this will reset that change back to the original value and then call ClearTrackedOriginalValues()

    Declaration
    public Dictionary<string, object> ResetChangedTrackedPropertiesToOriginalValues()
    Returns
    Type Description
    System.Collections.Generic.Dictionary<System.String, System.Object>

    A snapshot of all the values that were changed before they are reset -> the property name and its changed value

    RestoreFromSnapshot(Dictionary<String, Object>)

    Restores all properties for this entity using the provided dictionary of property name and values

    Declaration
    public void RestoreFromSnapshot(Dictionary<string, object> snapshot)
    Parameters
    Type Name Description
    System.Collections.Generic.Dictionary<System.String, System.Object> snapshot

    A complete list of all properties and associated values

    SetLabel(String, String)

    For properties that are Guid properties holding a relationship to another entity, this function can be used to set the label held for that id

    This is used throughout the client UI by the platform to update the labels held when users choose different items for relationships so the UI immediately reflects these choices

    This is done by the class that implements this interface holding a xxx_Label property for every xxx Guid relationship property with a label

    Declaration
    public void SetLabel(string propName, string value)
    Parameters
    Type Name Description
    System.String propName

    The Guid relationship property name to update the label for that item of

    System.String value

    The new label value for the corrosponding property id

    SetSilentLabel(String, String)

    The same as SetLabel(String, String) except done without raising any System.ComponentModel.INotifyPropertyChanged events

    Declaration
    public void SetSilentLabel(string propName, string value)
    Parameters
    Type Name Description
    System.String propName

    The Guid relationship property name to update the label for that item of

    System.String value

    The new label value for the corrosponding property id

    SnapshotProperties()

    Returns a snap shot of all the property values against this entity as a dictionary of property name/value

    Declaration
    public Dictionary<string, object> SnapshotProperties()
    Returns
    Type Description
    System.Collections.Generic.Dictionary<System.String, System.Object>

    A snap shot of all the property values against this entity as a dictionary of property name/value

    Events

    PropertyChanged

    System.ComponentModel.INotifyPropertyChanged Implementation

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

    PropertyChanging

    System.ComponentModel.INotifyPropertyChanging Implementation

    Declaration
    public event PropertyChangingEventHandler PropertyChanging
    Event Type
    Type Description
    System.ComponentModel.PropertyChangingEventHandler

    Implements

    IBaseEntity
    System.IEquatable<T>
    ICanTrackProperties
    System.ComponentModel.INotifyPropertyChanging
    System.ComponentModel.INotifyPropertyChanged
    ICloneableAsync

    Extension Methods

    MiscExtensions.SetIfNotEqual<T, P>(T, Expression<Func<T, P>>, P)
    ReflectionExtensions.ClearEventInvocations(Object, String)
    StringExtensions.ToCSVFormatString(Object, Type)
    SQLExtensions.ToSQLValue(Object, Boolean)
    In This Article
    Back to top © LemonEdge Technology. All rights reserved.