Zum Hauptinhalt springen

IDataSourceCollection<TKey, TDocument>

Namespace: Meshmakers.Octo.Runtime.Contracts.Repositories

Interface for the management of a collection of entities in a data source

public interface IDataSourceCollection<TKey, TDocument>

Type Parameters​

TKey

TDocument

Methods​

BulkImportAsync(IOctoSession, IEnumerable<TDocument>, BulkOperationOptions)​

Imports a list of documents into the collection

Task<IBulkImportResult> BulkImportAsync(IOctoSession session, IEnumerable<TDocument> documents, BulkOperationOptions options)

Parameters​

session IOctoSession
The session object

documents IEnumerable<TDocument>
The list of documents to import

options BulkOperationOptions
Options for the bulk operation

Returns​

Task<IBulkImportResult>
Returns the result of the import

InsertOneAsync(IOctoSession, TDocument)​

Inserts a new document into the collection

Task InsertOneAsync(IOctoSession session, TDocument document)

Parameters​

session IOctoSession
The session object

document TDocument
The document to insert

Returns​

Task

InsertManyAsync(IOctoSession, IEnumerable<TDocument>)​

Inserts multiple documents into the collection

Task InsertManyAsync(IOctoSession session, IEnumerable<TDocument> documents)

Parameters​

session IOctoSession

documents IEnumerable<TDocument>

Returns​

Task

UpdateOneAsync(IOctoSession, IEnumerable<TDocument>)​

Updates multiple documents in the collection

Task UpdateOneAsync(IOctoSession session, IEnumerable<TDocument> documents)

Parameters​

session IOctoSession
The session object

documents IEnumerable<TDocument>
A list of documents to update

Returns​

Task

Remarks:

Attention! This method updates existing attributes of a document. Not mentioned (or null) attributes are not updated.

UpdateOneIfGuardMatchesAsync(IOctoSession, TDocument, AttributeNewerThanGuard)​

Updates a single document if the optimistic-concurrency guard matches the persisted state. The write is silently skipped if the guard does not match, so a stale write cannot overwrite a more-recent one.

Task<bool> UpdateOneIfGuardMatchesAsync(IOctoSession session, TDocument document, AttributeNewerThanGuard guard)

Parameters​

session IOctoSession
The session object

document TDocument
Document with the new values; the id is taken from this document

guard AttributeNewerThanGuard
Guard expression that must be satisfied for the write to apply

Returns​

Task<Boolean>
true if the document was updated; false if the guard did not match — the document was either absent or had a value at the guard's AttributeNewerThanGuard.AttributePath greater than the guard's AttributeNewerThanGuard.NewValue.

UpdateOneIfVersionMatchesAsync(IOctoSession, TDocument, UInt64)​

Updates a single document only if the stored document still has expectedRtVersion (optimistic concurrency on RtVersion). Check and write are one atomic statement. The stored version is incremented like for every update.

Task<bool> UpdateOneIfVersionMatchesAsync(IOctoSession session, TDocument document, ulong expectedRtVersion)

Parameters​

session IOctoSession
The session object

document TDocument
Document with the new values; the id is taken from this document

expectedRtVersion UInt64
The version the caller read

Returns​

Task<Boolean>
true if the document was updated; false if it exists with a different version - nothing was written (the repository turns this into RtVersionConflictException).

Remarks:

A missing document raises the same not-found error as IDataSourceCollection<TKey, TDocument>.UpdateOneAsync(IOctoSession, IEnumerable<TDocument>).

UpdateOneWithRecordArrayItemsAsync(IOctoSession, TDocument, IReadOnlyCollection<RtRecordArrayItemUpdate>, Boolean)​

Updates a single document and, in the same atomic statement, single items of its RecordArray attributes (see RtRecordArrayItemUpdate). The stored document is not read first and no version is compared, so concurrent updates of different items of the same entity never lose each other; concurrent updates of the same item keep the last write.

Task<bool> UpdateOneWithRecordArrayItemsAsync(IOctoSession session, TDocument document, IReadOnlyCollection<RtRecordArrayItemUpdate> itemUpdates, bool requireItemMatch)

Parameters​

session IOctoSession
The session object

document TDocument
Document with the regular attribute updates (may carry no attributes); the id is taken from this document. The names and values of itemUpdates are already validated and converted.

itemUpdates IReadOnlyCollection<RtRecordArrayItemUpdate>
The item updates; at least one

requireItemMatch Boolean
true: the write is skipped when no item of any entry matches (the document carries nothing else to write). false: the regular attribute updates are written regardless; a missing document is an error as for IDataSourceCollection<TKey, TDocument>.UpdateOneAsync(IOctoSession, IEnumerable<TDocument>).

Returns​

Task<Boolean>
true if the document was written; false if requireItemMatch was set and the document is absent or none of the items matched - nothing was written (no version bump).

UpdateManyAsync(IOctoSession, Expression<Func<TDocument, Boolean>>, TDocument)​

Updates multiple documents in the collection based on a filter expression

Task UpdateManyAsync(IOctoSession session, Expression<Func<TDocument, bool>> expression, TDocument document)

Parameters​

session IOctoSession
The session object

expression Expression<Func<TDocument, Boolean>>
Filter expression to filter for documents that need to be updated

document TDocument
Document template with new values

Returns​

Task

ReplaceManyAsync(IOctoSession, IEnumerable<TDocument>)​

Replaces multiple documents in the collection

Task ReplaceManyAsync(IOctoSession session, IEnumerable<TDocument> documents)

Parameters​

session IOctoSession
The session object

documents IEnumerable<TDocument>
A list of documents to replaced, based on the runtime object id

Returns​

Task

ReplaceByIdAsync(IOctoSession, TKey, TDocument)​

Replace a document in the collection

Task ReplaceByIdAsync(IOctoSession session, TKey key, TDocument document)

Parameters​

session IOctoSession
The session object

key TKey
The unique key

document TDocument
The document the existing of is replaced

Returns​

Task

ReplaceByIdIfVersionMatchesAsync(IOctoSession, TKey, TDocument, UInt64)​

Replaces a document only if the stored document still has expectedRtVersion (optimistic concurrency on RtVersion). Check and write are one atomic statement. The caller sets the version of document to the new value (expected + 1) before the call; a replace does not increment on its own.

Task<bool> ReplaceByIdIfVersionMatchesAsync(IOctoSession session, TKey key, TDocument document, ulong expectedRtVersion)

Parameters​

session IOctoSession
The session object

key TKey
The unique key

document TDocument
The replacement document, already carrying the new version

expectedRtVersion UInt64
The version the caller read

Returns​

Task<Boolean>
true if the document was replaced; false if it exists with a different version - nothing was written (the repository turns this into RtVersionConflictException).

Remarks:

A missing document raises the same not-found error as IDataSourceCollection<TKey, TDocument>.ReplaceByIdAsync(IOctoSession, TKey, TDocument).

DeleteOneAsync(IOctoSession, TKey)​

Deletes the document with the given key

Task DeleteOneAsync(IOctoSession session, TKey key)

Parameters​

session IOctoSession
The session object

key TKey
The unique key

Returns​

Task

TryDeleteOneAsync(IOctoSession, TKey)​

Deletes the document with the given key without exceptions and with return value that indicates if the document has been deleted

Task<bool> TryDeleteOneAsync(IOctoSession session, TKey key)

Parameters​

session IOctoSession
The session object

key TKey
The unique key

Returns​

Task<Boolean>
True, when the document has been deleted, otherwise false

TryDeleteOneAsync(IOctoSession, Expression<Func<TDocument, Boolean>>)​

Deletes the first document that matches the given expression without exceptions and with return value that indicates if the document has been deleted

Task<bool> TryDeleteOneAsync(IOctoSession session, Expression<Func<TDocument, bool>> expression)

Parameters​

session IOctoSession
The session object

expression Expression<Func<TDocument, Boolean>>
Filter expression

Returns​

Task<Boolean>
True, when the document has been deleted, otherwise false

DeleteOneAsync(IOctoSession, IEnumerable<TKey>)​

Deletes documents with the given id

Task DeleteOneAsync(IOctoSession session, IEnumerable<TKey> keys)

Parameters​

session IOctoSession
The session object

keys IEnumerable<TKey>
A list of unique keys of the documents

Returns​

Task

DeleteManyAsync(IOctoSession, Expression<Func<TDocument, Boolean>>)​

Deletes all documents matching the given expression

Task DeleteManyAsync(IOctoSession session, Expression<Func<TDocument, bool>> expression)

Parameters​

session IOctoSession
The session object

expression Expression<Func<TDocument, Boolean>>
Filter expression

Returns​

Task

DocumentAsync(IOctoSession, TKey)​

Gets the document with the given key

Task<TDocument> DocumentAsync(IOctoSession session, TKey key)

Parameters​

session IOctoSession
The session object

key TKey
The unique key

Returns​

Task<TDocument>
The document or null if not found

DocumentsAsync(IOctoSession, IEnumerable<TKey>)​

Gets the document with the given key

Task<IReadOnlyList<TDocument>> DocumentsAsync(IOctoSession session, IEnumerable<TKey> keys)

Parameters​

session IOctoSession
The session object

keys IEnumerable<TKey>
A list of unique keys for the documents

Returns​

Task<IReadOnlyList<TDocument>>
A list of documents

DocumentAsync<TDerived>(IOctoSession, TKey)​

Gets the document with the given key

Task<TDerived> DocumentAsync<TDerived>(IOctoSession session, TKey key)

Type Parameters​

TDerived
The type of the derived document

Parameters​

session IOctoSession
The session object

key TKey
The unique key

Returns​

Task<TDerived>

AsQueryableAsync(IOctoSession)​

Gets a queryable interface of the given type to the data source

Task<IQueryable<TDocument>> AsQueryableAsync(IOctoSession session)

Parameters​

session IOctoSession
The session object

Returns​

Task<IQueryable<TDocument>>

AsQueryable(IOctoSession)​

Gets a queryable interface of the given type to the data source

IQueryable<TDocument> AsQueryable(IOctoSession session)

Parameters​

session IOctoSession
The session object

Returns​

IQueryable<TDocument>

FindSingleOrDefaultAsync(IOctoSession, Expression<Func<TDocument, Boolean>>)​

Finds a document by the given expression

Task<TDocument> FindSingleOrDefaultAsync(IOctoSession session, Expression<Func<TDocument, bool>> expression)

Parameters​

session IOctoSession
The session object

expression Expression<Func<TDocument, Boolean>>
Filter expression

Returns​

Task<TDocument>
The document

FindManyAsync(IOctoSession, Expression<Func<TDocument, Boolean>>, Nullable<Int32>, Nullable<Int32>)​

Finds a document by the given expression

Task<ICollection<TDocument>> FindManyAsync(IOctoSession session, Expression<Func<TDocument, bool>> expression, Nullable<int> skip, Nullable<int> take)

Parameters​

session IOctoSession
The session object

expression Expression<Func<TDocument, Boolean>>
Filter expression

skip Nullable<Int32>
Amount of documents to skip

take Nullable<Int32>
Maximum amount of documents to return

Returns​

Task<ICollection<TDocument>>
List of documents

GetTotalCountAsync(IOctoSession)​

Gets the total count of documents in the collection

Task<long> GetTotalCountAsync(IOctoSession session)

Parameters​

session IOctoSession
The session object

Returns​

Task<Int64>
Total count

GetTotalCountAsync(IOctoSession, Expression<Func<TDocument, Boolean>>)​

Gets the total count of documents in the collection that match the given filter

Task<long> GetTotalCountAsync(IOctoSession session, Expression<Func<TDocument, bool>> expression)

Parameters​

session IOctoSession
The session object

expression Expression<Func<TDocument, Boolean>>
Filter expression

Returns​

Task<Int64>
Total count

GetAsync(IOctoSession, Nullable<Int32>, Nullable<Int32>)​

Gets all documents of the collection

Task<IEnumerable<TDocument>> GetAsync(IOctoSession session, Nullable<int> skip, Nullable<int> take)

Parameters​

session IOctoSession
The session object

skip Nullable<Int32>
Amount of documents to skip

take Nullable<Int32>
Maximum amount of documents to return

Returns​

Task<IEnumerable<TDocument>>
List of documents