Search Results for

    Show / Hide Table of Contents

    Class Database

    A Database instance represents a session with the database and can be used to perform CRUD operations with your tables and entities.

    Inheritance
    Object
    Database
    Implements
    IDisposable
    Namespace: Venflow
    Assembly: Venflow.dll
    Syntax
    public abstract class Database : IAsyncDisposable, IDisposable
    Remarks

    Typically you create a class that derives from Database and contains Table<TEntity> properties for each entity in the Database. All the Table<TEntity> properties must have a public setter, they are automatically initialized when the instance of the derived type is created.

    Constructors

    | Improve this Doc View Source

    Database(DatabaseOptionsBuilder)

    Initializes a new instance of the Database class using the specified optionsBuilder.

    Declaration
    protected Database(DatabaseOptionsBuilder optionsBuilder)
    Parameters
    Type Name Description
    DatabaseOptionsBuilder optionsBuilder

    The options builder containing all the necessary information for the Database instance.

    | Improve this Doc View Source

    Database(String)

    Initializes a new instance of the Database class using the specified connectionString.

    Declaration
    protected Database(string connectionString)
    Parameters
    Type Name Description
    String connectionString

    The connection string to your PostgreSQL Database.

    Methods

    | Improve this Doc View Source

    BeginTransactionAsync(CancellationToken)

    Asynchronously begins a new transaction.

    Declaration
    public ValueTask<IDatabaseTransaction> BeginTransactionAsync(CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation

    Returns
    Type Description
    ValueTask<IDatabaseTransaction>

    A task that represents the asynchronous operation. The task result contains the newly created transaction.

    Remarks

    Be aware, that this method will not create a new transaction on every call. It will only create a new one, if the old one is disposed or not available.

    | Improve this Doc View Source

    BeginTransactionAsync(IsolationLevel, CancellationToken)

    Asynchronously begins a new transaction.

    Declaration
    public ValueTask<IDatabaseTransaction> BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    IsolationLevel isolationLevel

    The isolation level under which the transaction should run.

    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation

    Returns
    Type Description
    ValueTask<IDatabaseTransaction>

    A task that represents the asynchronous operation. The task result contains the newly created transaction.

    Remarks

    Be aware, that this method will not create a new transaction on every call. It will only create a new one, if the old one is disposed or not available.

    | Improve this Doc View Source

    Configure(DatabaseConfigurationOptionsBuilder)

    Allows for further configuration of the Database.

    Declaration
    protected virtual void Configure(DatabaseConfigurationOptionsBuilder optionsBuilder)
    Parameters
    Type Name Description
    DatabaseConfigurationOptionsBuilder optionsBuilder

    A builder instance used to further configure the Database.

    | Improve this Doc View Source

    Custom<TEntity>()

    Allows for queries against an entity which isn't usually defined, this is usually an entity which hasn't got a table in your database.

    Declaration
    public TableBase<TEntity> Custom<TEntity>()
        where TEntity : class, new()
    Returns
    Type Description
    TableBase<TEntity>

    A TableBase<TEntity> instance from which queries can be executed.

    Type Parameters
    Name Description
    TEntity
    Remarks

    The TEntity should always be used with this Database instance, otherwise the model has to be generated multiple times.

    | Improve this Doc View Source

    Dispose()

    Releases the allocated resources for this context. Also closes the underlying connection, if open.

    Declaration
    public void Dispose()
    Remarks

    If you are in an asynchronous context you should consider using DisposeAsync() instead.

    | Improve this Doc View Source

    DisposeAsync()

    Releases the allocated resources for this context. Also closes the underlying connection, if open.

    Declaration
    public ValueTask DisposeAsync()
    Returns
    Type Description
    ValueTask

    A value task representing the asynchronous operation

    | Improve this Doc View Source

    ExecuteAsync(String, CancellationToken)

    Asynchronously executes a command against the current Database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments.

    Declaration
    public Task<int> ExecuteAsync(string sql, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    String sql

    The SQL to execute.

    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation.

    Returns
    Type Description
    Task<Int32>

    A task representing the asynchronous operation, with the number of rows affected if known; -1 otherwise.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    ExecuteAsync(String, IList<NpgsqlParameter>, CancellationToken)

    Asynchronously executes a command against the current Database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments.

    Declaration
    public Task<int> ExecuteAsync(string sql, IList<NpgsqlParameter> parameters, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    String sql

    The SQL to execute.

    IList<NpgsqlParameter> parameters

    The SQL Parameters which are being used for the current command.

    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation.

    Returns
    Type Description
    Task<Int32>

    A task representing the asynchronous operation, with the number of rows affected if known; -1 otherwise.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    ExecuteAsync(String, NpgsqlParameter[])

    Asynchronously executes a command against the current Database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments.

    Declaration
    public Task<int> ExecuteAsync(string sql, params NpgsqlParameter[] parameters)
    Parameters
    Type Name Description
    String sql

    The SQL to execute.

    NpgsqlParameter[] parameters

    The SQL Parameters which are being used for the current command.

    Returns
    Type Description
    Task<Int32>

    A task representing the asynchronous operation, with the number of rows affected if known; -1 otherwise.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    ExecuteAsync<T>(String, CancellationToken)

    Asynchronously executes a command against the current Database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments.

    Declaration
    public Task<T> ExecuteAsync<T>(string sql, CancellationToken cancellationToken = null)
        where T : struct
    Parameters
    Type Name Description
    String sql

    The SQL to execute.

    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation.

    Returns
    Type Description
    Task<T>

    A task representing the asynchronous operation, with the value of the scalar command.

    Type Parameters
    Name Description
    T

    The type of the scalar result.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    ExecuteAsync<T>(String, IList<NpgsqlParameter>, CancellationToken)

    Asynchronously executes a command against the current Database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments.

    Declaration
    public Task<T> ExecuteAsync<T>(string sql, IList<NpgsqlParameter> parameters, CancellationToken cancellationToken = null)
        where T : struct
    Parameters
    Type Name Description
    String sql

    The SQL to execute.

    IList<NpgsqlParameter> parameters

    The SQL Parameters which are being used for the current command.

    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation.

    Returns
    Type Description
    Task<T>

    A task representing the asynchronous operation, with the value of the scalar command.

    Type Parameters
    Name Description
    T

    The type of the scalar result.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    ExecuteAsync<T>(String, NpgsqlParameter[])

    Asynchronously executes a command against the current Database. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments.

    Declaration
    public Task<T> ExecuteAsync<T>(string sql, params NpgsqlParameter[] parameters)
        where T : struct
    Parameters
    Type Name Description
    String sql

    The SQL to execute.

    NpgsqlParameter[] parameters

    The SQL Parameters which are being used for the current command.

    Returns
    Type Description
    Task<T>

    A task representing the asynchronous operation, with the value of the scalar command.

    Type Parameters
    Name Description
    T

    The type of the scalar result.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    ExecuteInterpolatedAsync(FormattableString, CancellationToken)

    Asynchronously executes a command against the current Database. This method does automatically parameterize queries from an interpolated string.

    Declaration
    public Task<int> ExecuteInterpolatedAsync(FormattableString sql, CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    FormattableString sql

    The interpolated SQL to execute.

    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation.

    Returns
    Type Description
    Task<Int32>

    A task representing the asynchronous operation, with the number of rows affected if known; -1 otherwise.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    ExecuteInterpolatedAsync<T>(FormattableString, CancellationToken)

    Asynchronously executes a command against the current Database. This method does automatically parameterize queries from an interpolated string.

    Declaration
    public Task<T> ExecuteInterpolatedAsync<T>(FormattableString sql, CancellationToken cancellationToken = null)
        where T : struct
    Parameters
    Type Name Description
    FormattableString sql

    The interpolated SQL to execute.

    CancellationToken cancellationToken

    The cancellation token, which is used to cancel the operation.

    Returns
    Type Description
    Task<T>

    A task representing the asynchronous operation, with the value of the scalar command.

    Type Parameters
    Name Description
    T

    The type of the scalar result.

    Remarks

    This method represents a call.

    | Improve this Doc View Source

    GetConnection()

    Gets or creates a new connections, if none got created yet.

    Declaration
    public NpgsqlConnection GetConnection()
    Returns
    Type Description
    NpgsqlConnection

    the .

    Implements

    IDisposable

    Theme

    • Improve this Doc
    • View Source
    Back to top Copyright © 2021 Twenty