Database
Bulk-load helpers extracted from the main Database file so the CRUD/transaction/cache concerns there don't have to coexist with the bulk-load state machine. Both inner classes remain private to Database via the partial-class split, keeping their access to its private members intact.
Herda de: Disposable
Implementa: IStorage, IQueryContext
Construtores
public Database(string name, string connectionString, DbProviderFactory factory, ISqlDialect dialect)
database = Database(name, connectionString, factory, dialect)
Initializes a new instance of the Database class.
Propriedades
public bool AllowDeleteAll { get; set; }
value = database.AllowDeleteAll
database.AllowDeleteAll = value
Gets or sets whether delete-all operations are permitted.
public TimeSpan CacheTimeout { get; set; }
value = database.CacheTimeout
database.CacheTimeout = value
Maximum age of an entity in the cache. Defaults to MaxValue meaning entries are never evicted based on age (the cache only grows / clears explicitly via CancellationToken)). Lower the value for long-running processes that risk OOM under unbounded growth, then call CancellationToken) on a timer.
public CommandType CommandType { get; set; }
value = database.CommandType
database.CommandType = value
Gets or sets the default command type for database commands.
public string ConnectionString { get; set; }
value = database.ConnectionString
database.ConnectionString = value
Gets or sets the database connection string.
public CultureInfo CultureInfo { get; set; }
value = database.CultureInfo
database.CultureInfo = value
Gets or sets the culture used for data conversions.
public ISqlDialect Dialect { get; set; }
value = database.Dialect
database.Dialect = value
Gets or sets the SQL dialect used for query generation.
public DbProviderFactory Factory { get; set; }
value = database.Factory
database.Factory = value
Gets or sets the DbProviderFactory used to create database objects.
public int MaxBulkLoadRows { get; set; }
value = database.MaxBulkLoadRows
database.MaxBulkLoadRows = value
Gets or sets the maximum number of rows to preload in bulk-load mode.
public int MaxCacheEntries { get; set; }
value = database.MaxCacheEntries
database.MaxCacheEntries = value
Maximum entry count of the cache before LRU eviction kicks in. MaxValue disables size-bounded eviction; lower the value for long-running processes that should bound their resident set.
public string Name { get; set; }
value = database.Name
database.Name = value
Gets or sets the database name.
public QueryProvider QueryProvider { get; }
value = database.QueryProvider
Gets the query provider used to generate SQL commands.
Métodos
public void ClearBulkLoad()
database.ClearBulkLoad()
Removes all bulk-load registrations and their cached data.
public virtual ValueTask<object> CreateAsync(Schema meta, IDbPersistable entity, CancellationToken cancellationToken)
result = database.CreateAsync(meta, entity, cancellationToken)
Creates (inserts) a new entity in the database asynchronously.
public ValueTask<DbConnection> CreateConnectionAsync(CancellationToken cancellationToken)
result = database.CreateConnectionAsync(cancellationToken)
Creates and opens a new database connection asynchronously.
public virtual ValueTask DeleteAllAsync<TEntity>(CancellationToken cancellationToken)
result = database.DeleteAllAsync(cancellationToken)
Deletes all entities of type from the database.
public virtual ValueTask<int> DeleteAsync<TEntity>(TEntity entity, CancellationToken cancellationToken)
result = database.DeleteAsync(entity, cancellationToken)
Deletes an entity from the database asynchronously and returns the number of affected rows.
protected override void DisposeManaged()
database.DisposeManaged()
Disposes the managed resources. Override this method to add custom clean up of managed resources.
public virtual ValueTask<SerializationItemCollection> Execute(DatabaseCommand command, SerializationItemCollection source, bool needRetVal, CancellationToken cancellationToken)
result = database.Execute(command, source, needRetVal, cancellationToken)
Executes a database command, optionally returning output values.
public ValueTask<TResult> ExecuteResultAsync<TSource, TResult>(Expression expression)
result = database.ExecuteResultAsync(expression)
Executes the specified query expression and returns a single result.
- expression
- The query expression to execute.
Retorna: The query result.
public virtual ValueTask<DatabaseCommand> GetCommand(Schema meta, SqlCommandTypes type, IReadOnlyList<SchemaColumn> keyColumns, IReadOnlyList<SchemaColumn> valueColumns, CancellationToken cancellationToken)
result = database.GetCommand(meta, type, keyColumns, valueColumns, cancellationToken)
Gets or creates a cached DatabaseCommand for the specified schema and command type.
public virtual ValueTask<long> GetCountAsync<TEntity>(CancellationToken cancellationToken)
result = database.GetCountAsync(cancellationToken)
Gets the total number of entities of type in the database.
private static TResult[] MaterializeByCtor<TResult>(SerializationItemCollection table)
result = Database.MaterializeByCtor(table)
Materializes the projected rows into by matching the longest constructor whose parameters all map to projected columns, then assigning any remaining columns to writable properties by name. This covers anonymous types and positional records (full ctor) as well as the new Named { A = ..., B = ... } object-initializer shape (parameterless ctor + property setters).
public virtual ValueTask<object> Read(DatabaseCommand command, Schema meta, SerializationItemCollection input, CancellationToken cancellationToken)
result = database.Read(command, meta, input, cancellationToken)
Reads a single entity using the specified command and input parameters.
public virtual ValueTask<object[]> ReadAllAsync(Schema meta, long startIndex, long count, bool deleted, string orderByColumn, ListSortDirection direction, CancellationToken cancellationToken)
result = database.ReadAllAsync(meta, startIndex, count, deleted, orderByColumn, direction, cancellationToken)
Reads a paged set of entities from the database asynchronously.
public virtual ValueTask<object[]> ReadAllAsync(DatabaseCommand command, Schema meta, SerializationItemCollection input, CancellationToken cancellationToken)
result = database.ReadAllAsync(command, meta, input, cancellationToken)
Reads all entities matching the specified command and input parameters.
public virtual ValueTask<object> ReadAsync(Schema meta, object id, Func<Schema, ValueTask<DatabaseCommand>> getCommand, Func<Schema, ValueTask<SerializationItem>> getIdItem, CancellationToken cancellationToken)
result = database.ReadAsync(meta, id, getCommand, getIdItem, cancellationToken)
Reads a single entity by identity from the database asynchronously.
public ValueTask Test(CancellationToken cancellationToken)
result = database.Test(cancellationToken)
Tests the internal cache for incomplete entries and throws if any are found.
public ValueTask TrimExpiredCache(CancellationToken cancellationToken)
result = database.TrimExpiredCache(cancellationToken)
Removes entries from the cache whose age exceeds CacheTimeout. Safe to call concurrently with normal CRUD — it acquires the same lock used by ClearCacheAsync.
public virtual ValueTask<TEntity> UpdateAsync<TEntity>(TEntity entity, CancellationToken cancellationToken)
result = database.UpdateAsync(entity, cancellationToken)
Updates an existing entity in the database asynchronously.
private static bool UsesCtorProjection(Type t)
result = Database.UsesCtorProjection(t)
Executes a LINQ expression and returns a single result asynchronously.