Table of Contents

Interface IDatabase

Namespace
GroupeIsa.Neos.Domain.Persistence
Assembly
GroupeIsa.Neos.Domain.Abstractions.dll

Represents an abstraction of Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.

public interface IDatabase

Remarks

See Microsoft documentation and examples for additional informations.

Properties

DatabaseType

Gets the database type.

DatabaseType DatabaseType { get; }

Property Value

DatabaseType

QuotedIdentifiers

Gets a value indicating whether quoted identifiers are used.

bool QuotedIdentifiers { get; }

Property Value

bool

Methods

ExecuteSql(FormattableString)

Executes the given SQL against the database and returns the number of rows affected.

int ExecuteSql(FormattableString sql)

Parameters

sql FormattableString

The interpolated string representing a SQL query with parameters.

Returns

int

The number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

See Executing raw SQL commands with EF Core for more information and examples.

ExecuteSqlAsync(FormattableString, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

Task<int> ExecuteSqlAsync(FormattableString sql, CancellationToken cancellationToken = default)

Parameters

sql FormattableString

The interpolated string representing a SQL query with parameters.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<int>

A task that represents the asynchronous operation. The task result is the number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

See Executing raw SQL commands with EF Core for more information and examples.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

ExecuteSqlInterpolated(FormattableString)

Executes the given SQL against the database and returns the number of rows affected.

int ExecuteSqlInterpolated(FormattableString sql)

Parameters

sql FormattableString

The interpolated string representing a SQL query with parameters.

Returns

int

The number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

See Executing raw SQL commands with EF Core for more information and examples.

ExecuteSqlInterpolatedAsync(FormattableString, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

Task<int> ExecuteSqlInterpolatedAsync(FormattableString sql, CancellationToken cancellationToken = default)

Parameters

sql FormattableString

The interpolated string representing a SQL query with parameters.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<int>

A task that represents the asynchronous operation. The task result is the number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

See Executing raw SQL commands with EF Core for more information and examples.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

ExecuteSqlRaw(string, IEnumerable<object>)

Executes the given SQL against the database and returns the number of rows affected.

int ExecuteSqlRaw(string sql, IEnumerable<object> parameters)

Parameters

sql string

The SQL to execute.

parameters IEnumerable<object>

Parameters to use with the SQL.

Returns

int

The number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

However, never pass a concatenated or interpolated string ($"") with non-validated user-provided values into this method. Doing so may expose your application to SQL injection attacks. To use the interpolated string syntax, consider using ExecuteSql(FormattableString) to create parameters.

See Executing raw SQL commands with EF Core for more information and examples.

ExecuteSqlRaw(string, params object[])

Executes the given SQL against the database and returns the number of rows affected.

int ExecuteSqlRaw(string sql, params object[] parameters)

Parameters

sql string

The SQL to execute.

parameters object[]

Parameters to use with the SQL.

Returns

int

The number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

However, never pass a concatenated or interpolated string ($"") with non-validated user-provided values into this method. Doing so may expose your application to SQL injection attacks. To use the interpolated string syntax, consider using ExecuteSql(FormattableString) to create parameters.

See Executing raw SQL commands with EF Core for more information and examples.

ExecuteSqlRawAsync(string, IEnumerable<object>, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

Task<int> ExecuteSqlRawAsync(string sql, IEnumerable<object> parameters, CancellationToken cancellationToken = default)

Parameters

sql string

The SQL to execute.

parameters IEnumerable<object>

Parameters to use with the SQL.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<int>

A task that represents the asynchronous operation. The task result is the number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

However, never pass a concatenated or interpolated string ($"") with non-validated user-provided values into this method. Doing so may expose your application to SQL injection attacks. To use the interpolated string syntax, consider using ExecuteSqlAsync(FormattableString, CancellationToken) to create parameters.

See Executing raw SQL commands with EF Core for more information and examples.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

ExecuteSqlRawAsync(string, params object[])

Executes the given SQL against the database and returns the number of rows affected.

Task<int> ExecuteSqlRawAsync(string sql, params object[] parameters)

Parameters

sql string

The SQL to execute.

parameters object[]

Parameters to use with the SQL.

Returns

Task<int>

A task that represents the asynchronous operation. The task result is the number of rows affected.

Remarks

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. Any parameter values you supply will automatically be converted to a DbParameter.

However, never pass a concatenated or interpolated string ($"") with non-validated user-provided values into this method. Doing so may expose your application to SQL injection attacks. To use the interpolated string syntax, consider using ExecuteSqlAsync(FormattableString, CancellationToken) to create parameters.

See Executing raw SQL commands with EF Core for more information and examples.

ExecuteSqlRawAsync(string, CancellationToken)

Executes the given SQL against the database and returns the number of rows affected.

Task<int> ExecuteSqlRawAsync(string sql, CancellationToken cancellationToken = default)

Parameters

sql string

The SQL to execute.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<int>

A task that represents the asynchronous operation. The task result is the number of rows affected.

Remarks

Never pass a concatenated or interpolated string ($"") with non-validated user-provided values into this method. Doing so may expose your application to SQL injection attacks.

See Executing raw SQL commands with EF Core for more information and examples.

Exceptions

OperationCanceledException

If the CancellationToken is canceled.

GetConnectionString(bool)

Gets the connection string.

string GetConnectionString(bool hideUserIdAndPassword = true)

Parameters

hideUserIdAndPassword bool

A value indicating whether user id and password should be hidden.

Returns

string

The connection string.

SqlQueryRaw<TResult>(string, params object[])

Creates a LINQ query based on a raw SQL query, which returns a result set of a scalar type natively supported by the database provider.

IQueryable<TResult> SqlQueryRaw<TResult>(string sql, params object[] parameters)

Parameters

sql string

The raw SQL query.

parameters object[]

The values to be assigned to parameters.

Returns

IQueryable<TResult>

An IQueryable<T> representing the raw SQL query.

Type Parameters

TResult

Result type.

Remarks

The returned IQueryable<T> can be composed over using LINQ to build more complex queries.

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. Any parameter values you supply will automatically be converted to a DbParameter.

However, never pass a concatenated or interpolated string ($"") with non-validated user-provided values into this method. Doing so may expose your application to SQL injection attacks. To use the interpolated string syntax, consider using SqlQuery<TResult>(FormattableString) to create parameters.

See Executing raw SQL commands with EF Core for more information and examples.

SqlQuery<TResult>(FormattableString)

Creates a LINQ query based on a raw SQL query, which returns a result set of a scalar type natively supported by the database provider.

IQueryable<TResult> SqlQuery<TResult>(FormattableString sql)

Parameters

sql FormattableString

The interpolated string representing a SQL query with parameters.

Returns

IQueryable<TResult>

An IQueryable<T> representing the interpolated string SQL query.

Type Parameters

TResult

Result type.

Remarks

The returned IQueryable<T> can be composed over using LINQ to build more complex queries.

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. Any parameter values you supply will automatically be converted to a DbParameter.

See Executing raw SQL commands with EF Core for more information and examples.