Table of Contents

Class CloudStorageDatabase

Namespace
CloudStorageORM.Infrastructure
Assembly
CloudStorageORM.dll

IDatabase implementation that persists EF entity changes to object storage.

public class CloudStorageDatabase : IDatabase
Inheritance
CloudStorageDatabase
Implements
Inherited Members

Constructors

CloudStorageDatabase(IModel, IDatabaseCreator, IExecutionStrategyFactory, IStorageProvider, ICurrentDbContext, IBlobPathResolver, IDbContextTransactionManager, CloudStorageOptions?, ILoggerFactory?, ILogger<CloudStorageDatabase>?)

IDatabase implementation that persists EF entity changes to object storage.

public CloudStorageDatabase(IModel model, IDatabaseCreator databaseCreator, IExecutionStrategyFactory executionStrategyFactory, IStorageProvider storageProvider, ICurrentDbContext currentDbContext, IBlobPathResolver blobPathResolver, IDbContextTransactionManager transactionManager, CloudStorageOptions? cloudStorageOptions = null, ILoggerFactory? loggerFactory = null, ILogger<CloudStorageDatabase>? logger = null)

Parameters

model IModel
databaseCreator IDatabaseCreator
executionStrategyFactory IExecutionStrategyFactory
storageProvider IStorageProvider
currentDbContext ICurrentDbContext
blobPathResolver IBlobPathResolver
transactionManager IDbContextTransactionManager
cloudStorageOptions CloudStorageOptions
loggerFactory ILoggerFactory
logger ILogger<CloudStorageDatabase>

Properties

ExecutionStrategyFactory

public IExecutionStrategyFactory ExecutionStrategyFactory { get; }

Property Value

IExecutionStrategyFactory

Model

public IModel Model { get; }

Property Value

IModel

Methods

CompileQueryExpression<TResult>(Expression, bool)

Compiles a query expression into an executable delegate.

public Expression<Func<QueryContext, TResult>> CompileQueryExpression<TResult>(Expression query, bool async)

Parameters

query Expression

Query expression to compile.

async bool

Whether query compilation targets async execution.

Returns

Expression<Func<QueryContext, TResult>>

A compiled query delegate.

Type Parameters

TResult

Compiled query result type.

Exceptions

NotImplementedException

Always thrown in the current implementation.

CompileQueryExpression<TResult>(Expression, bool, IReadOnlySet<string>)

Compiles a query expression into an executable delegate.

public Expression<Func<QueryContext, TResult>> CompileQueryExpression<TResult>(Expression query, bool async, IReadOnlySet<string> nonNullableReferenceTypeParameters)

Parameters

query Expression

Query expression to compile.

async bool

Whether query compilation targets async execution.

nonNullableReferenceTypeParameters IReadOnlySet<string>

Set of non-nullable parameter names.

Returns

Expression<Func<QueryContext, TResult>>

A compiled query delegate.

Type Parameters

TResult

Compiled query result type.

Exceptions

NotImplementedException

Always thrown in the current implementation.

CompileQuery<TResult>(Expression, bool)

public Func<QueryContext, TResult> CompileQuery<TResult>(Expression query, bool async)

Parameters

query Expression
async bool

Returns

Func<QueryContext, TResult>

Type Parameters

TResult

EnsureCreatedAsync(CancellationToken)

Ensures the backing store is created for the current provider.

public Task EnsureCreatedAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token for the async operation.

Returns

Task

A task that completes when creation has been verified or performed.

EnsureDeletedAsync(CancellationToken)

Ensures the backing store is deleted for the current provider.

public Task EnsureDeletedAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token for the async operation.

Returns

Task

A task that completes when deletion has been verified or performed.

LoadByPrimaryKeyRangeAsync<TEntity>(object?, bool, object?, bool, DbContext?)

Loads entities whose primary keys are within the provided range and attaches them to the context.

public Task<IList<TEntity>> LoadByPrimaryKeyRangeAsync<TEntity>(object? lowerBound, bool lowerInclusive, object? upperBound, bool upperInclusive, DbContext? context = null) where TEntity : class

Parameters

lowerBound object

Optional lower bound key value.

lowerInclusive bool

true to include the lower bound.

upperBound object

Optional upper bound key value.

upperInclusive bool

true to include the upper bound.

context DbContext

Optional context used for tracking; defaults to the current context.

Returns

Task<IList<TEntity>>

Entities whose storage keys satisfy the specified range.

Type Parameters

TEntity

Entity type to load.

Examples

var users = await database.LoadByPrimaryKeyRangeAsync<User>(100, true, 200, false);

LoadByPrimaryKeyRangePageAsync<TEntity>(object?, bool, object?, bool, int, int, DbContext?)

Loads a paged slice of entities whose primary keys are in the provided range.

public Task<IList<TEntity>> LoadByPrimaryKeyRangePageAsync<TEntity>(object? lowerBound, bool lowerInclusive, object? upperBound, bool upperInclusive, int skip, int take, DbContext? context = null) where TEntity : class

Parameters

lowerBound object

Optional lower bound key value.

lowerInclusive bool

true to include the lower bound.

upperBound object

Optional upper bound key value.

upperInclusive bool

true to include the upper bound.

skip int

Number of matching entities to skip.

take int

Maximum number of matching entities to load.

context DbContext

Optional context used for tracking; defaults to the current context.

Returns

Task<IList<TEntity>>

A page of entities whose keys satisfy the requested range after applying skip/take.

Type Parameters

TEntity

Entity type to load.

LoadEntitiesAsync<TEntity>(DbContext)

Loads all entities of a given type and attaches them to the provided DbContext.

public Task<IList<TEntity>> LoadEntitiesAsync<TEntity>(DbContext context) where TEntity : class

Parameters

context DbContext

DbContext used for tracking loaded entities.

Returns

Task<IList<TEntity>>

All existing entities for the requested type.

Type Parameters

TEntity

Entity type to load.

Examples

var users = await database.LoadEntitiesAsync<User>(context);

LoadPageAsync<TEntity>(int, int, DbContext?)

Loads a paged slice of entities for the requested type using provider-native key listing.

public Task<IList<TEntity>> LoadPageAsync<TEntity>(int skip, int take, DbContext? context = null) where TEntity : class

Parameters

skip int

Number of matching entities to skip.

take int

Maximum number of matching entities to load.

context DbContext

Optional context used for tracking; defaults to the current context.

Returns

Task<IList<TEntity>>

A page of entities after applying skip/take.

Type Parameters

TEntity

Entity type to load.

SaveChanges(IList<IUpdateEntry>)

Persists pending update entries to object storage synchronously.

public int SaveChanges(IList<IUpdateEntry> entries)

Parameters

entries IList<IUpdateEntry>

Update entries representing tracked entity changes.

Returns

int

The number of persisted changes.

SaveChangesAsync(IList<IUpdateEntry>, CancellationToken)

Persists pending update entries to object storage asynchronously.

public Task<int> SaveChangesAsync(IList<IUpdateEntry> entries, CancellationToken cancellationToken = default)

Parameters

entries IList<IUpdateEntry>

Update entries representing tracked entity changes.

cancellationToken CancellationToken

Cancellation token for the async operation.

Returns

Task<int>

The number of persisted changes.

ToListAsync<TEntity>(string)

Loads all entities for the specified blob prefix and attaches them to the current context.

public Task<IList<TEntity>> ToListAsync<TEntity>(string containerName) where TEntity : class

Parameters

containerName string

Blob prefix or folder name to enumerate.

Returns

Task<IList<TEntity>>

A list containing all deserialized entities found under the prefix.

Type Parameters

TEntity

Entity type to load.

Examples

var users = await database.ToListAsync<User>("users");

TryLoadByPrimaryKeyAsync<TEntity>(object, DbContext?)

Loads a single entity by primary-key value from object storage and attaches it to the context.

public Task<TEntity?> TryLoadByPrimaryKeyAsync<TEntity>(object keyValue, DbContext? context = null) where TEntity : class

Parameters

keyValue object

Primary-key value used to resolve the blob path.

context DbContext

Optional context used for tracking; defaults to the current context.

Returns

Task<TEntity>

The loaded entity when found; otherwise null.

Type Parameters

TEntity

Entity type to load.

Examples

var user = await database.TryLoadByPrimaryKeyAsync<User>(42);