Database

Ecng.Data

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.

Erbt von: Disposable

Implementiert: IStorage, IQueryContext

Konstruktoren

Database
public Database(string name, string connectionString, DbProviderFactory factory, ISqlDialect dialect)
database = Database(name, connectionString, factory, dialect)

Initializes a new instance of the Database class.

Eigenschaften

AllowDeleteAll
public bool AllowDeleteAll { get; set; }
value = database.AllowDeleteAll
database.AllowDeleteAll = value

Gets or sets whether delete-all operations are permitted.

CacheTimeout
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.

CommandType
public CommandType CommandType { get; set; }
value = database.CommandType
database.CommandType = value

Gets or sets the default command type for database commands.

ConnectionString
public string ConnectionString { get; set; }
value = database.ConnectionString
database.ConnectionString = value

Gets or sets the database connection string.

CultureInfo
public CultureInfo CultureInfo { get; set; }
value = database.CultureInfo
database.CultureInfo = value

Gets or sets the culture used for data conversions.

Dialect
public ISqlDialect Dialect { get; set; }
value = database.Dialect
database.Dialect = value

Gets or sets the SQL dialect used for query generation.

Factory
public DbProviderFactory Factory { get; set; }
value = database.Factory
database.Factory = value

Gets or sets the DbProviderFactory used to create database objects.

MaxBulkLoadRows
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.

MaxCacheEntries
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.

Name
public string Name { get; set; }
value = database.Name
database.Name = value

Gets or sets the database name.

QueryProvider
public QueryProvider QueryProvider { get; }
value = database.QueryProvider

Gets the query provider used to generate SQL commands.

Methoden

ClearBulkLoad
public void ClearBulkLoad()
database.ClearBulkLoad()

Removes all bulk-load registrations and their cached data.

CreateAsync
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.

CreateConnectionAsync
public ValueTask<DbConnection> CreateConnectionAsync(CancellationToken cancellationToken)
result = database.CreateConnectionAsync(cancellationToken)

Creates and opens a new database connection asynchronously.

DeleteAllAsync``1
public virtual ValueTask DeleteAllAsync<TEntity>(CancellationToken cancellationToken)
result = database.DeleteAllAsync(cancellationToken)

Deletes all entities of type from the database.

DeleteAsync``1
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.

DisposeManaged
protected override void DisposeManaged()
database.DisposeManaged()

Disposes the managed resources. Override this method to add custom clean up of managed resources.

Execute
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.

ExecuteResultAsync``2
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.

Rückgabe: The query result.

GetCommand
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.

GetCountAsync``1
public virtual ValueTask<long> GetCountAsync<TEntity>(CancellationToken cancellationToken)
result = database.GetCountAsync(cancellationToken)

Gets the total number of entities of type in the database.

MaterializeByCtor``1
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).

Read
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.

ReadAllAsync
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.

ReadAllAsync
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.

ReadAsync
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.

Test
public ValueTask Test(CancellationToken cancellationToken)
result = database.Test(cancellationToken)

Tests the internal cache for incomplete entries and throws if any are found.

TrimExpiredCache
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.

UpdateAsync``1
public virtual ValueTask<TEntity> UpdateAsync<TEntity>(TEntity entity, CancellationToken cancellationToken)
result = database.UpdateAsync(entity, cancellationToken)

Updates an existing entity in the database asynchronously.

UsesCtorProjection
private static bool UsesCtorProjection(Type t)
result = Database.UsesCtorProjection(t)

Executes a LINQ expression and returns a single result asynchronously.