Skip to main content
Version: 8.3

Entity class

Level: advanced

Terrasoft.Core.Entities namespace.

The Terrasoft.Core.Entities.Entity class provides access to an object that represents a record in the database table.

note

View the entire list of properties of the Entity class, its parent classes, as well as the interfaces it implements, in the .NET classes reference.

Constructors

Entity(UserConnection userConnection)

Creates a new Entity class instance for the set UserConnection user connection.


Entity(UserConnection userConnection, Guid schemaUId)

Creates a new Entity class instance for the set UserConnection user connection and the schema set by the schemaUId identifier.


Entity(Entity source)

Creates a class instance that is a clone of the instance passed as an argument.


Properties

EntityLoadState

The object load state.

Available values

NotLoaded

PartialLoaded

Loaded


EntityChangeType

The type of object status change.

Available values

None

0

Inserted

1

Updated

2

Deleted

4


EntitySchemaManager EntitySchemaManager

An instance of the Object schema manager.


EntitySchemaManagerName string

The name of the Object schema manager.


HasColumnValues bool

Whether an object instance has at least one column.


HierarchyColumnValue Guid

The value of the column that binds the parent record, for hierarchical objects.


InstanceUId Guid

The object instance identifier.


IsDeletedFromDB bool

Whether the object is deleted from the database.


IsInColumnValueChanged bool

Whether to handle the ColumnValueChanged event.


IsInColumnValueChanging bool

Whether to handle the ColumnValueChanging event.


IsInDefColumnValuesSet bool

Whether to handle the DefColumnValuesSet event.


IsInDeleted bool

Whether to handle the Deleted event.


IsInDeleting bool

Whether to handle the Deleting event.


IsInInserted bool

Whether to handle the Inserted event.


IsInInserting bool

Whether to handle the Inserting event.


IsInLoaded bool

Whether to handle the Loaded event.


IsInLoading bool

Whether to handle the Loading event.


IsInSaved bool

Whether to handle the Saved event.


IsInSaveError bool

Whether to handle the SaveError event.


IsInSaving bool

Whether to handle the Saving event.


IsInUpdated bool

Whether to handle the Updated event.


IsInUpdating bool

Whether to handle the Updating event.


IsInValidating bool

Whether to handle the Validating event.


IsSchemaInitialized bool

Whether the "Object" type schema is initialized.


LicOperationPrefix string

The prefix of the operation to license.


PrimaryColumnValue Guid

The ID of the primary column.


PrimaryDisplayColumnValue string

The value to display in the initial column.


Process Process

The nested process of the object.


Schema EntitySchema

An instance of the "Object" type schema.


SchemaName string

The name of the "Object" type schema.


StoringState StoringObjectState

The record status (modified, added, deleted, unchanged).


UseAdminRights bool

Whether to apply permissions when inserting, updating, deleting, and retrieving data.


UseDefRights bool

Whether to use the default object permissions.


UseLazyLoad bool

Whether to use the lazy initial loading of object data.


UserConnection UserConnection

The user connection.


ValidationMessages EntityValidationMessageCollection

The message collection displayed when validating an object.


ValueListSchemaManager ValueListSchemaManager

An instance of the Object enumerations manager.


ValueListSchemaManagerName string

The name of the Object enumerations manager.


Methods

void AddDefRights()
void AddDefRights(Guid primaryColumnValue)
void AddDefRights(IEnumerable<Guid> primaryColumnValues)

Sets the default permissions for the object.

Parameters

primaryColumnValue

The ID of the access permission value.

primaryColumnValues

An array of IDs of the access permission values.


virtual object Clone()

Creates a clone of the current Entity instance.


Insert CreateInsert(bool skipLookupColumnValues)

Creates a query to add data to the database.

Parameters

skipLookupColumnValues

Whether to take the lookup columns into account while adding data. By default, false.


Update CreateUpdate(bool skipLookupColumnValues)

Creates a query to update data in the database.

Parameters

skipLookupColumnValues

Whether to add the columns of the lookup type to the database. If set to true, Creatio will not add the columns of the lookup type to the database. By default, false.


virtual bool Delete()
virtual bool Delete(object keyValue)

Deletes the object record from the database.

Parameters

keyValue

The key field value.


bool DeleteWithCancelProcess()

Deletes the object record from the database and cancels the started process.


static Entity DeserializeFromJson(UserConnection userConnection, string jsonValue)

Creates an Entity type object using the userConnection user connection and populates the object field values from the specified jsonValue JSON string.

Parameters

jsonValue

A JSON string.

userConnection

The user connection.


bool ExistInDB(EntitySchemaColumn conditionColumn, object conditionValue)
bool ExistInDB(string conditionColumnName, object conditionValue)
bool ExistInDB(object keyValue)
bool ExistInDB(Dictionary<string,object> conditions)

Whether the database contains a record that matches the given condition of the conditionValue query to the conditionColumn object schema column or with the specified keyValue initial key.

Parameters

conditionColumn

The column for which to specify the selection condition.

conditionColumnName

The name of the column for which to specify the selection condition.

conditionValue

The value of the condition column for the selected data.

conditions

A set of conditions to filter the object record selection.

keyValue

The key field value.


bool FetchFromDB(EntitySchemaColumn conditionColumn, object conditionValue, bool useDisplayValues)
bool FetchFromDB(string conditionColumnName, object conditionValue, bool useDisplayValues)
bool FetchFromDB(object keyValue, bool useDisplayValues)
bool FetchFromDB(Dictionary<string,object> conditions, bool useDisplayValues)
bool FetchFromDB(EntitySchemaColumn conditionColumn, object conditionValue, IEnumerable<EntitySchemaColumn> columnsToFetch, bool useDisplayValues)
bool FetchFromDB(string conditionColumnName, object conditionValue, IEnumerable<string>columnNamesToFetch, bool useDisplayValues)

Loads the object from the database by the specified condition.

Parameters

conditionColumn

The column for which to specify the selection condition.

conditionColumnName

The name of the column for which to specify the selection condition.

conditionValue

The value of the condition column for the selected data.

columnsToFetch

The list of columns to select.

columnNamesToFetch

The list of column names to select.

conditions

A set of conditions to filter the object record selection.

keyValue

The key field value.

useDisplayValues

Indicates that the query returns the initial displayed values. If set to true, the query will return the initial displayed values.


bool FetchPrimaryColumnFromDB(object keyValue)

Loads the object with the initial column from the database by the set keyValue condition.

Parameters

keyValue

The key field value.


bool FetchPrimaryInfoFromDB(EntitySchemaColumn conditionColumn, object conditionValue)
bool FetchPrimaryInfoFromDB(string conditionColumnName, object conditionValue)

Loads a database object with initial columns, including the initial displayed column, by the set condition.

Parameters

conditionColumn

The column for which to specify the selection condition.

conditionColumnName

The name of the column for which to specify the selection condition.

conditionValue

The value of the condition column for the selected data.


byte[] GetBytesValue(string valueName)

Returns the value of the specified object column as a byte array.

Parameters

valueName

The name of the object column.


IEnumerable<EntityColumnValue> GetChangedColumnValues()

Returns the name collection of the object columns that were modified.


string GetColumnDisplayValue(EntitySchemaColumn column)

Returns the value for the display of the object column that matches the specified column of the "Object" type schema.

Parameters

column

A specific column of the "Object" type schema.


object GetColumnOldValue(string valueName)
object GetColumnOldValue(EntitySchemaColumn column)

Returns the previous value of the specified "Object" type schema column.

Parameters

column

A specific column of the "Object" type schema.

valueName

The column name of the "Object" type schema.


virtual object GetColumnValue(string valueName)
virtual object GetColumnValue(EntitySchemaColumn column)

Returns the value of the object column with the specified name that matches the passed column of the "Object" type schema.

Parameters

column

A specific column of the "Object" type schema.

valueName

The column name of the "Object" type schema.


IEnumerable<string> GetColumnValueNames()

Returns the collection of object column names.


virtual bool GetIsColumnValueLoaded(string valueName)
bool GetIsColumnValueLoaded(EntitySchemaColumn column)

Returns the flag that determines whether the specified object column is loaded.

Parameters

column

A specific column of the "Object" type schema.

valueName

The column name of the "Object" type schema.


virtual MemoryStream GetStreamValue(string valueName)

Returns the value of the passed object schema column converted into the System.IO.MemoryStream type instance.

Parameters

valueName

The column name of the "Object" type schema.


TResult GetTypedColumnValue<TResult>(EntitySchemaColumn column)

Returns the typed value of the object column that matches the specified column of the "Object" type schema.

Parameters

column

A specific column of the "Object" type schema.


TResult GetTypedOldColumnValue<TResult>(string valueName)
TResult GetTypedOldColumnValue<TResult>(EntitySchemaColumn column)

Returns the typed previous value of the object column that matches the specified column of the "Object" type schema.

Parameters

column

A specific column of the "Object" type schema.

valueName

The column name of the "Object" type schema.


virtual bool InsertToDB(bool skipLookupColumnValues, bool validateRequired)

Adds a record of the current object to the database.

Parameters

skipLookupColumnValues

Whether to add the columns of the lookup type to the database. If set to true, Creatio will not add the columns of the lookup type to the database. By default, false.

validateRequired

Whether to validate the required values. By default, true.


bool IsColumnValueLoaded(string valueName)
bool IsColumnValueLoaded(EntitySchemaColumn column)

Whether the value of the object column with the specified name is loaded.

Parameters

column

A specific column of the "Object" type schema.

valueName

The column name of the "Object" type schema.


virtual bool Load(DataRow dataRow)
virtual bool Load(DataRow dataRow, Dictionary<string,string> columnMap)
virtual bool Load(IDataReader dataReader)
virtual bool Load(IDataReader dataReader, IDictionary<string,string> columnMap)
virtual bool Load(object dataSource)
virtual bool Load(object dataSource, IDictionary<string,string> columnMap)

Populates the object with the passed data.

Parameters

columnMap

The object columns to populate with data.

dataRow

A System.Data.DataRow instance from which to load the data to the object.

dataReader

A System.Data.IDataReader instance from which to load the data to the object.

dataSource

A System.Object instance from which to load the data to the object.


void LoadColumnValue(string columnValueName, IDataReader dataReader, int fieldIndex, int binaryPackageSize)
void LoadColumnValue(string columnValueName, IDataReader dataReader, int fieldIndex)
void LoadColumnValue(string columnValueName, object value)
void LoadColumnValue(EntitySchemaColumn column, object value)

Loads the value from the passed instance for the column with the specified name.

Parameters

binaryPackageSize

The size of the loaded value.

column

The column of the "Object" type schema.

columnValueName

The column name of the "Object" type schema.

dataReader

A System.Data.IDataReader instance from which to load the column value.

fieldIndex

The index of the field loaded from System.Data.IDataReader.

value

The loaded value of the column.


static Entity Read(UserConnection userConnection, DataReader dataReader)

Returns the current column value of the Entity type from the input stream.

Parameters

dataReader

A System.Data.IDataReader instance from which to load the property value.

userConnection

The user connection.


void ReadData(DataReader reader)
void ReadData(DataReader reader, EntitySchema schema)

Reads data from the "Object" type schema and saves the data to the specified object of the System.Data.IDataReader type.

Parameters

reader

A System.Data.IDataReader instance to which to load the object data.

schema

The "Object" type schema.


void ResetColumnValues();

Cancels the changes for all object columns.


void ResetOldColumnValues();

Reverts all object columns to previous values.


bool Save(bool validateRequired)

Saves the record to the database.

Parameters

validateRequired

Whether to validate the required values. By default, true.


static string SerializeToJson(Entity entity)

Converts the Entity object into a JSON string.

Parameters

entity

The Entity instance.


virtual void SetBytesValue(string valueName, byte[] streamBytes)

Sets the specified column to the passed value of the System.Byte type.

Parameters

streamBytes

A value of the System.Byte type set for the specified object column.

valueName

The name of the object column.


bool SetColumnBothValues(EntitySchemaColumn column, object value, string displayValue)
bool SetColumnBothValues(string columnValueName, object value, string displayColumnValueName, string displayValue)

Sets the object column to passed value and displayValue.

Parameters

column

The object schema column.

displayValue

The loaded value for display.

displayColumnValueName

The name of the column that contains the value for display.

value

The loaded value of the column.


bool SetColumnValue(string valueName, object value)
bool SetColumnValue(EntitySchemaColumn column, object value)

Sets the specified schema column to the passed value.

Parameters

column

The object schema column.

value

The loaded value of the column.

valueName

The name of the object column.


void SeddefColumnValue(string columnValueName, object defValue)
void SeddefColumnValue(string columnValueName)

Sets the column with the specified name to the default value.

Parameters

columnValueName

The name of the object column.

defValue

The default value.


void SeddefColumnValues();

Sets default values for all object columns.


bool SetStreamValue(string valueName, Stream value)

Sets the specified object column to the passed value of the System.IO.Stream type.

Parameters

value

The loaded value of the column.

valueName

The name of the object column.


virtual bool UpdateInDB(bool validateRequired)

Updates the object record in the database.

Parameters

validateRequired

Whether to validate the required values. By default, true.


bool Validate()

Verifies if the required fields are populated.


static void Write(DataWriter dataWriter, Entity entity, string propertyName)
static void Write(DataWriter dataWriter, Entity entity, string propertyName, bool couldConvertForXml)

Writes the value of the Entity type to the output stream with the specified name.

Parameters

couldConvertForXml

Allow converting for XML serialization.

dataWriter

An instance of the Terrasoft.Common.DataWriter class that provides methods for writing values to the output stream sequentially.

entity

A value for a record of the Entity type.

propertyName

The object name.


void Write(DataWriter dataWriter, string propertyName)

Writes the data to the output stream with the specified name.

Parameters

dataWriter

An instance of the Terrasoft.Common.DataWriter class that provides methods for writing values to the output stream sequentially.

propertyName

The object column.


void WriteData(DataWriter writer)
void WriteData(DataWriter writer, EntitySchema schema)

Writes to the output stream for the specified or current object schema.

Parameters

schema

The object schema.

writer

An instance of the Terrasoft.Common.DataWriter class that provides methods for writing values to the output stream sequentially.


Events

event EventHandler<EntityColumnAfterEventArgs> ColumnValueChanged

Event handler used after modifying the object column value.

The event handler receives an argument of the EntityColumnAfterEventArgs type.

The EntityColumnAfterEventArgs properties that provide information relevant to the event:

  • ColumnValueName
  • DisplayColumnValueName

event EventHandler<EntityColumnBeforeEventArgs> ColumnValueChanging

Event handler used before modifying the object column value.

The event handler receives an argument of the EntityColumnBeforeEventArgs type.

The EntityColumnBeforeEventArgs properties that provide information relevant to the event:

  • ColumnStreamValue
  • ColumnValue
  • ColumnValueName
  • DisplayColumnValue
  • DisplayColumnValueName

event EventHandler<EventArgs> DefColumnValuesSet

Event handler used after setting default object column values.


event EventHandler<EntityAfterEventArgs> Deleted

Event handler used after deleting an object.

The event handler receives an argument of the EntityAfterEventArgs type.

The EntityAfterEventArgs properties that provide information relevant to the event:

  • ModifiedColumnValues
  • PrimaryColumnValue

event EventHandler<EntityBeforeEventArgs> Deleting

Event handler used before deleting an object.

The event handler receives an argument of the EntityBeforeEventArgs type.

The EntityBeforeEventArgs properties that provide information relevant to the event:

  • AdditionalCondition
  • IsCanceled
  • KeyValue

event EventHandler<EntityAfterEventArgs> Inserted

Event handler used after inserting an object.

The event handler receives an argument of the EntityAfterEventArgs type.

The EntityAfterEventArgs properties that provide information relevant to the event:

  • ModifiedColumnValues
  • PrimaryColumnValue

event EventHandler<EntityBeforeEventArgs> Inserting

Event handler used before inserting an object.

The event handler receives an argument of the EntityBeforeEventArgs type.

The EntityBeforeEventArgs properties that provide information relevant to the event:

  • AdditionalCondition
  • IsCanceled
  • KeyValue

event EventHandler<EntityAfterLoadEventArgs> Loaded

Event handler used after loading an object.

The event handler receives an argument of the EntityAfterLoadEventArgs type.

The EntityAfterLoadEventArgs properties that provide information relevant to the event:

  • ColumnMap
  • DataSource

event EventHandler<EntityBeforeLoadEventArgs> Loading

Event handler used before loading an object.

The event handler receives an argument of the EntityBeforeLoadEventArgs type.

The EntityBeforeLoadEventArgs properties that provide information relevant to the event:

  • ColumnMap
  • DataSource
  • IsCanceled

event EventHandler<EntityAfterEventArgs> Saved

Event handler used after saving an entity.

The event handler receives an argument of the EntityAfterEventArgs type.

The EntityAfterEventArgs properties that provide information relevant to the event:

  • ModifiedColumnValues
  • PrimaryColumnValue

event EventHandler<EntitySaveErrorEventArgs> SaveError

Event handler used if an error occurs while saving an object.

The event handler receives an argument of the EntitySaveErrorEventArgs type.

The EntitySaveErrorEventArgs properties that provide information relevant to the event:

  • Exception
  • IsHandled

event EventHandler<EntityBeforeEventArgs> Saving

Event handler used before saving an object.

The event handler receives an argument of the EntityBeforeEventArgs type.

The EntityBeforeEventArgs properties that provide information relevant to the event:

  • AdditionalCondition
  • IsCanceled
  • KeyValue

event EventHandler<EntityAfterEventArgs> Updated

Event handler used after updating an object.

The event handler receives an argument of the EntityAfterEventArgs type.

The EntityAfterEventArgs properties that provide information relevant to the event:

  • ModifiedColumnValues
  • PrimaryColumnValue

event EventHandler<EntityBeforeEventArgs> Updating

Event handler used before updating an object.

The event handler receives an argument of the EntityBeforeEventArgs type.

The EntityBeforeEventArgs properties that provide information relevant to the event:

  • AdditionalCondition
  • IsCanceled
  • KeyValue

event EventHandler<EntityValidationEventArgs> Validating

Event handler used when validating an object.

The event handler receives an argument of the EntityValidationEventArgs type.

The EntityValidationEventArgs properties that provide information relevant to the event:

  • Messages