SQL Server · Types · Services and connections
IArxBatchScope
Definition
- Namespace
ARX.SDK.Services- Package
ARX.SDK
public interface IArxBatchScope : IAsyncDisposableOne transaction across many write calls. Nothing written through the scope is visible to other connections until CommitAsync. Disposing a scope that wasn't committed rolls it back, also when an exception is passing through. Not thread-safe: make one call at a time (a concurrent call fails with ARX1014).
Properties
ArxBatchState State { get; }The scope's state.
int BatchCount { get; }The number of calls made through the scope, successful or not. Reads count too. Each call's number (1-based) is its batch number.
long RowsWritten { get; }Rows written by successful calls that are still in the transaction; 0 once the scope is rolled back.
IReadOnlyList<int> FailedBatches { get; }The batch numbers of the calls that failed, in order.
Methods
Task<ArxRecordId> CreateAsync(ArxEntity entity, CancellationToken cancellationToken = default)Inserts one entity inside the scope's transaction and returns its id, which is also set on
RecordId.Parameter Type Description entityArxEntityThe record to create: its table and the attributes to write. Its RecordIdis set to the new id.cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, CancellationToken cancellationToken = default)Inserts the entities inside the scope's transaction, all or nothing, and returns their ids: one per entity, in list order, the same instances that are set on each entity's
RecordId. An empty list returns an empty list.Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing; their ids come back in the same order. cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateAsync(ArxEntity entity, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)Updates the rows
entitymatches inside the scope's transaction and returns how many changed. Nothing matched is ARX2002.Parameter Type Description entityArxEntityThe change: its table, the attributes to write (null clears a column; an attribute left out keeps its value), and the id, key or columns that find the row. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxUpdateOptions? options = null, CancellationToken cancellationToken = default)Updates the entities inside the scope's transaction, all or nothing, and returns the rows changed. An entity that matched nothing refuses the whole call (ARX2002). An empty list returns 0.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The changes, all or nothing: each carries the attributes to write and what finds its row. optionsArxUpdateOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> UpdateMultipleAsync(ArxEntity values, ArxFilterExpression filter, ArxFilterWriteOptions? options = null, CancellationToken cancellationToken = default)The update by a filter inside the scope's transaction: returns how many rows changed.
Parameter Type Description valuesArxEntityThe table (EntityName) and the attributes to set: null clears a column. filterArxFilterExpressionThe rows to change: conditions on the table's own columns. optionsArxFilterWriteOptions?= nullAllRows for an empty filter; null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(string entityName, ArxFilterExpression filter, ArxFilterWriteOptions? options = null, CancellationToken cancellationToken = default)The delete by a filter inside the scope's transaction: returns how many rows went.
Parameter Type Description entityNamestringThe table to delete from. filterArxFilterExpressionThe rows to delete: conditions on the table's own columns. optionsArxFilterWriteOptions?= nullAllRows for an empty filter; null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<IReadOnlyList<ArxRecordId>> CreateMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxCreateMultipleOptions options, CancellationToken cancellationToken = default)CreateMultiple with options inside the scope's transaction.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to create, all or nothing. optionsArxCreateMultipleOptionsReturnIds false to skip reading the ids back. cancellationTokenCancellationToken= defaultCancels the call. Task<bool> DeleteAsync(string entityName, ArxRecordId id, CancellationToken cancellationToken = default)Deletes the record with this id inside the scope's transaction; false when there was none. The id converts from a
long,int,Guidorstring, soDeleteAsync("account", 42L)works as it is.Parameter Type Description entityNamestringThe table to delete from. idArxRecordIdThe record's id: the value Create returned, or a plain value of the declared id's type. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteAsync(ArxEntity entity, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)Deletes the rows
entitymatches inside the scope's transaction and returns how many went.Parameter Type Description entityArxEntityThe record to delete: its table and the id, key or columns that find it. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync<TId>(string entityName, IReadOnlyCollection<TId> ids, CancellationToken cancellationToken = default)Deletes the records with these ids inside the scope's transaction, all or nothing, and returns how many existed. Duplicates count once. One method for every id type: a list of
long,int,Guid,stringorArxRecordId; another element type is ARX1007 UnsupportedValueType.Parameter Type Description entityNamestringThe table to delete from. idsIReadOnlyCollection<TId>The ids of the records to delete; ids that match nothing are left out of the count. cancellationTokenCancellationToken= defaultCancels the call. Task<int> DeleteMultipleAsync(IReadOnlyList<ArxEntity> entities, ArxDeleteOptions? options = null, CancellationToken cancellationToken = default)Deletes the rows the entities match inside the scope's transaction, all or nothing, and returns how many went.
Parameter Type Description entitiesIReadOnlyList<ArxEntity>The records to delete, all or nothing, each found by its id or by the match's columns. optionsArxDeleteOptions?= nullHow the rows are found ( Match) and checked; null for the defaults (by id).cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntity?> RetrieveAsync(string entityName, ArxRecordId id, ArxColumnSet? columns = null, CancellationToken cancellationToken = default)Reads one record by id (the value Create returned, or a
long,int,Guidorstring) inside the scope's transaction; null when not found. On the SQL providers and MongoDB it sees the scope's own writes; DynamoDB sends writes at commit, so a read before it sees only what is committed.Parameter Type Description entityNamestringThe table or view to read. idArxRecordIdThe record's id: the value Create returned, or a plain value of the declared id's type. columnsArxColumnSet?= nullThe columns to read; null or an empty set reads every column. The declared id is always read. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntity?> RetrieveAsync(ArxEntity match, ArxRetrieveOptions? options = null, CancellationToken cancellationToken = default)Reads the one record the entity matches (an ArxMatch in
Match) inside the scope's transaction.Parameter Type Description matchArxEntityThe record to find: its table, and the values of the id, the declared key or the columns that find it. optionsArxRetrieveOptions?= nullHow the row is found and read (match, command timeout, lookup names); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxEntityCollection> RetrieveMultipleAsync(ArxQueryExpression query, ArxRetrieveOptions? options = null, CancellationToken cancellationToken = default)Runs a query inside the scope's transaction. On the SQL providers and MongoDB it sees the scope's own writes; on DynamoDB, only what is committed.
Parameter Type Description queryArxQueryExpressionThe query: its row source, columns, criteria, links, order, paging and aggregates. optionsArxRetrieveOptions?= nullHow the row is found and read (match, command timeout, lookup names); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task<ArxExecuteResult> ExecuteAsync(ArxProcedureExpression procedure, ArxExecuteOptions? options = null, CancellationToken cancellationToken = default)Calls a procedure or function inside the scope's transaction: it sees the scope's writes, and a failed call is undone alone. A procedure that commits or rolls back by itself can't run in a scope (ARX8001).
Parameter Type Description procedureArxProcedureExpressionThe procedure or function to call, with its arguments. optionsArxExecuteOptions?= nullOptions of the call (paging, command timeout); null for the defaults. cancellationTokenCancellationToken= defaultCancels the call. Task CommitAsync(CancellationToken cancellationToken = default)Commits everything written through the scope. If the database refuses the commit (for example a deferred constraint), the error is thrown and the scope is
RolledBack. If the connection fails or times out before the database answers, the scope isOutcomeUnknownand the error, not transient, says the work may or may not be saved. A token cancelled before the commit starts rolls the scope back; the commit itself isn't cancelled, because stopping it half way would leave its outcome unknown.Parameter Type Description cancellationTokenCancellationToken= defaultCancels the call. Task RollbackAsync(CancellationToken cancellationToken = default)Rolls back everything written through the scope. Does nothing if the scope is already rolled back; fails with ARX1010 if it was committed. The rollback itself isn't cancelled.
Parameter Type Description cancellationTokenCancellationToken= defaultCancels the call.
Usage
Used in: