Table of Contents

Class OrpheusTable<T>

Namespace
OrpheusCore
Assembly
OrpheusCore.dll

Orpheus table is the core component of an Orpheus module. Every module needs to have at least 1 table. Holds all the data of the connected table.

public class OrpheusTable<T> : IOrpheusTable<T>, IOrpheusTable, IDisposable

Type Parameters

T

Model type

Inheritance
OrpheusTable<T>
Implements
Inherited Members

Constructors

OrpheusTable(IOrpheusDatabase, List<IOrpheusTableKeyField>, ILogger<IOrpheusTable<T>>, string, IOrpheusTable, List<IOrpheusTableKeyField>)

Orpheus table constructor.

public OrpheusTable(IOrpheusDatabase database, List<IOrpheusTableKeyField> keyFields, ILogger<IOrpheusTable<T>> logger, string tableName = null, IOrpheusTable masterTable = null, List<IOrpheusTableKeyField> masterTableKeyFields = null)

Parameters

database IOrpheusDatabase

Orpheus database

keyFields List<IOrpheusTableKeyField>

Table key fields.

logger ILogger<IOrpheusTable<T>>

The logger

tableName string

Table name

masterTable IOrpheusTable

Master table (optional)

masterTableKeyFields List<IOrpheusTableKeyField>

Master table key fields (optional)

OrpheusTable(IOrpheusTableOptions, ILogger<IOrpheusTable<T>>)

Initializes a new instance of the OrpheusTable<T> class.

public OrpheusTable(IOrpheusTableOptions options, ILogger<IOrpheusTable<T>> logger)

Parameters

options IOrpheusTableOptions

The options.

logger ILogger<IOrpheusTable<T>>

The logger

Properties

BatchSize

public int BatchSize { get; set; }

Property Value

int

Maximum number of rows batched into a single round trip when executing queued inserts/updates/deletes. Default: 100 — empirically, larger batches (e.g. 250) trade fewer round trips for more expensive per-batch statement compilation, which can net out worse, especially for updates (each row still needs its own full UPDATE statement, unlike insert's compact multi-row VALUES). Tune per workload/engine if needed.

Data

public List<T> Data { get; }

Property Value

List<T>

Table's currently loaded data.

DetailTables

public List<IOrpheusTable> DetailTables { get; }

Property Value

List<IOrpheusTable>

Associated detail tables.

KeyFields

public List<IOrpheusTableKeyField> KeyFields { get; set; }

Property Value

List<IOrpheusTableKeyField>

Table key fields.

Level

public int Level { get; }

Property Value

int

Table level.

MasterTable

public IOrpheusTable MasterTable { get; set; }

Property Value

IOrpheusTable

Associated master table.

MasterTableKeyFields

public List<IOrpheusTableKeyField> MasterTableKeyFields { get; }

Property Value

List<IOrpheusTableKeyField>

Table master table's key fields.

Modified

public bool Modified { get; }

Property Value

bool

Modified flag.

Name

public string Name { get; set; }

Property Value

string

Table name.

SchemaName

public string SchemaName { get; }

Property Value

string

The table's schema name. Applicable only if the db engine is SQL Server.

Methods

Add(List<T>)

Adds a list of new records.

public void Add(List<T> newRecords)

Parameters

newRecords List<T>

New records to be added

Add(T)

Adds a new record to the table.

public void Add(T newRecord)

Parameters

newRecord T

New record to be added

ClearData()

Clears existing loaded data.

public void ClearData()

Delete(List<T>)

Deletes records.

public void Delete(List<T> records)

Parameters

records List<T>

Records to be deleted

Delete(T)

Deletes a record.

public void Delete(T record)

Parameters

record T

Record to delete

Dispose()

Disposes the table and its commands.

public void Dispose()

Dispose(bool)

Disposes managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

ExecuteDeletes(IDbTransaction)

Executes any delete changes that the table has.

public void ExecuteDeletes(IDbTransaction transaction)

Parameters

transaction IDbTransaction

The transaction.

ExecuteInserts(IDbTransaction)

Executes any insert changes that the table has.

public void ExecuteInserts(IDbTransaction transaction)

Parameters

transaction IDbTransaction

The transaction.

ExecuteUpdates(IDbTransaction)

Executes any update changes that the table has.

public void ExecuteUpdates(IDbTransaction transaction)

Parameters

transaction IDbTransaction

The transaction.

GetKeyValues()

public List<KeyValuePair<string, object>> GetKeyValues()

Returns

List<KeyValuePair<string, object>>

Returns list of currently loaded key values. It's purpose is to be used on a master-detail schema where this will be used from the detail tables in order to load their data based on the current master record. It's highly inadvisable to be used outside this scope.

Load(Dictionary<string, List<object>>, LogicalOperator, bool)

Loads records from the DB to the table. You can configure having multiple fields and multiple values per field. Multiple field values are bound with a logical OR. Multiple fields by default are bound with a logical OR. Defining a logical operator, you can change the default behavior.

public void Load(Dictionary<string, List<object>> keyValues = null, LogicalOperator logicalOperator = LogicalOperator.loOR, bool clearExistingData = true)

Parameters

keyValues Dictionary<string, List<object>>

The key values.

logicalOperator LogicalOperator

The logical operator.

clearExistingData bool

If true, it will clear all existing data. Default is true.

Load(List<object>, bool)

Loads records from the DB to the table.

public void Load(List<object> keyValues = null, bool clearExistingData = true)

Parameters

keyValues List<object>

The key values.

clearExistingData bool

If true, it will clear all existing data. Default is true.

Exceptions

InvalidExpressionException

When an Orpheus table has more than one key fields, you cannot use the 'simple' load. Values for each field much be determined.

Load(IDbCommand, bool)

Loads table data by executing a db command.

public void Load(IDbCommand dbCommand, bool clearExistingData = true)

Parameters

dbCommand IDbCommand

The IDbCommand instance.

clearExistingData bool

If true, it will clear all existing data. Default is true.

Load(string, bool)

Loads table data by executing a SQL command.

public void Load(string SQL, bool clearExistingData = true)

Parameters

SQL string

SQL command to be executed

clearExistingData bool

If true, it will clear all existing data. Default is true.

LoadAsync(List<object>, CancellationToken)

Asynchronously loads data using key-value pair filter.

public Task LoadAsync(List<object> keyValues, CancellationToken cancellationToken = default)

Parameters

keyValues List<object>
cancellationToken CancellationToken

Returns

Task

LoadAsync(IDbCommand, bool, CancellationToken)

Asynchronously loads table data by executing a db command.

public Task LoadAsync(IDbCommand dbCommand, bool clearExistingData = true, CancellationToken cancellationToken = default)

Parameters

dbCommand IDbCommand
clearExistingData bool
cancellationToken CancellationToken

Returns

Task

LoadAsync(string, bool, CancellationToken)

Asynchronously loads table data by executing a SQL command.

public Task LoadAsync(string SQL, bool clearExistingData = true, CancellationToken cancellationToken = default)

Parameters

SQL string
clearExistingData bool
cancellationToken CancellationToken

Returns

Task

LoadAsync(CancellationToken)

Asynchronously loads data from the database into the table.

public Task LoadAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

Save(IDbTransaction, bool)

Save changes to the database.

public void Save(IDbTransaction dbTransaction = null, bool commitTransaction = true)

Parameters

dbTransaction IDbTransaction

Transaction in which the commands will be executed

commitTransaction bool

Commit transaction after save.

SaveAsync(CancellationToken)

Asynchronously saves all pending changes.

public Task SaveAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

Update(List<T>)

Updates existing records.

public void Update(List<T> records)

Parameters

records List<T>

Records to be updated

Update(T)

Updates an existing record.

public void Update(T record)

Parameters

record T

Record to be updated

executeDelete(IDbTransaction)

Executes deletes, chunked into batches of BatchSize rows per round trip.

protected void executeDelete(IDbTransaction transaction)

Parameters

transaction IDbTransaction

executeDeleteAsync(IDbTransaction, CancellationToken)

Asynchronously executes deletes, chunked into batches of BatchSize rows per round trip.

protected Task executeDeleteAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)

Parameters

transaction IDbTransaction
cancellationToken CancellationToken

Returns

Task

executeInsert(IDbTransaction)

Executes inserts. Tables without DB-generated keys are batched into BatchSize-row round trips. Tables with a DB-generated key are also batched into BatchSize-row round trips, using the engine-specific key-retrieval strategy on IOrpheusDDLHelper (only a single DB-generated key column is supported).

protected void executeInsert(IDbTransaction transaction)

Parameters

transaction IDbTransaction

executeInsertAsync(IDbTransaction, CancellationToken)

Asynchronously executes inserts. See executeInsert(IDbTransaction) for the batching rules.

protected Task executeInsertAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)

Parameters

transaction IDbTransaction
cancellationToken CancellationToken

Returns

Task

executeUpdate(IDbTransaction)

Executes updates, chunked into batches of BatchSize rows per round trip.

protected void executeUpdate(IDbTransaction transaction)

Parameters

transaction IDbTransaction

executeUpdateAsync(IDbTransaction, CancellationToken)

Asynchronously executes updates.

protected Task executeUpdateAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)

Parameters

transaction IDbTransaction
cancellationToken CancellationToken

Returns

Task

Events

OnAfterModify

public event EventHandler<IModifyRecordEventArguments<T>> OnAfterModify

Event Type

EventHandler<IModifyRecordEventArguments<T>>

Occurs after a table modifies a record. It is fired on any Add,Update,Delete

OnAfterSave

public event EventHandler<ISaveEventArguments> OnAfterSave

Event Type

EventHandler<ISaveEventArguments>

Occurs after the transaction has been committed.

OnBeforeModify

public event EventHandler<IModifyRecordEventArguments<T>> OnBeforeModify

Event Type

EventHandler<IModifyRecordEventArguments<T>>

Occurs before a table modifies a record. It is fired on any Add,Update,Delete

OnBeforeSave

public event EventHandler<ISaveEventArguments> OnBeforeSave

Event Type

EventHandler<ISaveEventArguments>

Occurs before records are save in the database.