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
modelIModeldatabaseCreatorIDatabaseCreatorexecutionStrategyFactoryIExecutionStrategyFactorystorageProviderIStorageProvidercurrentDbContextICurrentDbContextblobPathResolverIBlobPathResolvertransactionManagerIDbContextTransactionManagercloudStorageOptionsCloudStorageOptionsloggerFactoryILoggerFactoryloggerILogger<CloudStorageDatabase>
Properties
ExecutionStrategyFactory
public IExecutionStrategyFactory ExecutionStrategyFactory { get; }
Property Value
Model
public IModel Model { get; }
Property Value
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
queryExpressionQuery expression to compile.
asyncboolWhether query compilation targets async execution.
Returns
- Expression<Func<QueryContext, TResult>>
A compiled query delegate.
Type Parameters
TResultCompiled 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
queryExpressionQuery expression to compile.
asyncboolWhether query compilation targets async execution.
nonNullableReferenceTypeParametersIReadOnlySet<string>Set of non-nullable parameter names.
Returns
- Expression<Func<QueryContext, TResult>>
A compiled query delegate.
Type Parameters
TResultCompiled 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
queryExpressionasyncbool
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
cancellationTokenCancellationTokenCancellation 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
cancellationTokenCancellationTokenCancellation 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
lowerBoundobjectOptional lower bound key value.
lowerInclusivebooltrue to include the lower bound.
upperBoundobjectOptional upper bound key value.
upperInclusivebooltrue to include the upper bound.
contextDbContextOptional context used for tracking; defaults to the current context.
Returns
Type Parameters
TEntityEntity 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
lowerBoundobjectOptional lower bound key value.
lowerInclusivebooltrue to include the lower bound.
upperBoundobjectOptional upper bound key value.
upperInclusivebooltrue to include the upper bound.
skipintNumber of matching entities to skip.
takeintMaximum number of matching entities to load.
contextDbContextOptional 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
TEntityEntity 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
contextDbContextDbContext used for tracking loaded entities.
Returns
Type Parameters
TEntityEntity 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
skipintNumber of matching entities to skip.
takeintMaximum number of matching entities to load.
contextDbContextOptional context used for tracking; defaults to the current context.
Returns
Type Parameters
TEntityEntity type to load.
SaveChanges(IList<IUpdateEntry>)
Persists pending update entries to object storage synchronously.
public int SaveChanges(IList<IUpdateEntry> entries)
Parameters
entriesIList<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
entriesIList<IUpdateEntry>Update entries representing tracked entity changes.
cancellationTokenCancellationTokenCancellation token for the async operation.
Returns
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
containerNamestringBlob prefix or folder name to enumerate.
Returns
Type Parameters
TEntityEntity 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
keyValueobjectPrimary-key value used to resolve the blob path.
contextDbContextOptional context used for tracking; defaults to the current context.
Returns
Type Parameters
TEntityEntity type to load.
Examples
var user = await database.TryLoadByPrimaryKeyAsync<User>(42);