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
TModel 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
databaseIOrpheusDatabaseOrpheus database
keyFieldsList<IOrpheusTableKeyField>Table key fields.
loggerILogger<IOrpheusTable<T>>The logger
tableNamestringTable name
masterTableIOrpheusTableMaster table (optional)
masterTableKeyFieldsList<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
optionsIOrpheusTableOptionsThe options.
loggerILogger<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
newRecordsList<T>New records to be added
Add(T)
Adds a new record to the table.
public void Add(T newRecord)
Parameters
newRecordTNew record to be added
ClearData()
Clears existing loaded data.
public void ClearData()
Delete(List<T>)
Deletes records.
public void Delete(List<T> records)
Parameters
recordsList<T>Records to be deleted
Delete(T)
Deletes a record.
public void Delete(T record)
Parameters
recordTRecord to delete
Dispose()
Disposes the table and its commands.
public void Dispose()
Dispose(bool)
Disposes managed resources.
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
ExecuteDeletes(IDbTransaction)
Executes any delete changes that the table has.
public void ExecuteDeletes(IDbTransaction transaction)
Parameters
transactionIDbTransactionThe transaction.
ExecuteInserts(IDbTransaction)
Executes any insert changes that the table has.
public void ExecuteInserts(IDbTransaction transaction)
Parameters
transactionIDbTransactionThe transaction.
ExecuteUpdates(IDbTransaction)
Executes any update changes that the table has.
public void ExecuteUpdates(IDbTransaction transaction)
Parameters
transactionIDbTransactionThe 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
keyValuesDictionary<string, List<object>>The key values.
logicalOperatorLogicalOperatorThe logical operator.
clearExistingDataboolIf 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
keyValuesList<object>The key values.
clearExistingDataboolIf 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
dbCommandIDbCommandThe IDbCommand instance.
clearExistingDataboolIf 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
SQLstringSQL command to be executed
clearExistingDataboolIf 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
keyValuesList<object>cancellationTokenCancellationToken
Returns
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
dbCommandIDbCommandclearExistingDataboolcancellationTokenCancellationToken
Returns
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
SQLstringclearExistingDataboolcancellationTokenCancellationToken
Returns
LoadAsync(CancellationToken)
Asynchronously loads data from the database into the table.
public Task LoadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Save(IDbTransaction, bool)
Save changes to the database.
public void Save(IDbTransaction dbTransaction = null, bool commitTransaction = true)
Parameters
dbTransactionIDbTransactionTransaction in which the commands will be executed
commitTransactionboolCommit transaction after save.
SaveAsync(CancellationToken)
Asynchronously saves all pending changes.
public Task SaveAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
Update(List<T>)
Updates existing records.
public void Update(List<T> records)
Parameters
recordsList<T>Records to be updated
Update(T)
Updates an existing record.
public void Update(T record)
Parameters
recordTRecord to be updated
executeDelete(IDbTransaction)
Executes deletes, chunked into batches of BatchSize rows per round trip.
protected void executeDelete(IDbTransaction transaction)
Parameters
transactionIDbTransaction
executeDeleteAsync(IDbTransaction, CancellationToken)
Asynchronously executes deletes, chunked into batches of BatchSize rows per round trip.
protected Task executeDeleteAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)
Parameters
transactionIDbTransactioncancellationTokenCancellationToken
Returns
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
transactionIDbTransaction
executeInsertAsync(IDbTransaction, CancellationToken)
Asynchronously executes inserts. See executeInsert(IDbTransaction) for the batching rules.
protected Task executeInsertAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)
Parameters
transactionIDbTransactioncancellationTokenCancellationToken
Returns
executeUpdate(IDbTransaction)
Executes updates, chunked into batches of BatchSize rows per round trip.
protected void executeUpdate(IDbTransaction transaction)
Parameters
transactionIDbTransaction
executeUpdateAsync(IDbTransaction, CancellationToken)
Asynchronously executes updates.
protected Task executeUpdateAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)
Parameters
transactionIDbTransactioncancellationTokenCancellationToken
Returns
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.