Show / Hide Table of Contents

Interface IDbContext

Interface that represents the concrete class responsible for handling EF (Entity Framework) Core contexts.

Inherited Members
System.IDisposable.Dispose()
Namespace: StoneCo.Framework.Data.SqlServer.Contexts
Assembly: cs.temp.dll.dll
Syntax
public interface IDbContext : IDisposable

Methods

BeginTransaction()

Starts a new transaction.

Declaration
IDbContextTransaction BeginTransaction()
Returns
Type Description
IDbContextTransaction

A transaction against the database.

ExecuteRawSql<TValueObject>(String, IDictionary<String, Object>)

Synchronous method that execute SQL query on database and map result value to ValueObject.

Declaration
IEnumerable<TValueObject> ExecuteRawSql<TValueObject>(string sql, IDictionary<string, object> parameters = null)
    where TValueObject : ValueObject<TValueObject>
Parameters
Type Name Description
System.String sql

SQL query to execute on database.

IDictionary<System.String, System.Object> parameters

Key and value as parameter of the query.

Returns
Type Description
IEnumerable<TValueObject>

Collection of the value object according result to query.

Type Parameters
Name Description
TValueObject

The type of the model used in the instance of the value object.

ExecuteRawSqlAsync<TValueObject>(String, IDictionary<String, Object>)

Asynchronous method that execute SQL query on database and map result value to ValueObject.

Declaration
Task<IEnumerable<TValueObject>> ExecuteRawSqlAsync<TValueObject>(string sql, IDictionary<string, object> parameters = null)
    where TValueObject : ValueObject<TValueObject>
Parameters
Type Name Description
System.String sql

SQL query to execute on database.

IDictionary<System.String, System.Object> parameters

Key and value as parameter of the query.

Returns
Type Description
System.Threading.Tasks.Task<IEnumerable<TValueObject>>

Collection of the value object according result to query.

Type Parameters
Name Description
TValueObject

The type of the model used in the instance of the value object.

ExecuteSqlCommand(String, IDictionary<String, Object>)

Synchronous method that execute SQL command on database.

note

Use to execute store procedure or sql script to insert, update or delete.

Declaration
int ExecuteSqlCommand(string sql, IDictionary<string, object> parameters = null)
Parameters
Type Name Description
System.String sql

SQL script to execute on database.

IDictionary<System.String, System.Object> parameters

Key and value as parameter of the query.

Returns
Type Description
System.Int32

ExecuteSqlCommandAsync(String, IDictionary<String, Object>)

Asynchronous method that execute SQL command on database.

note

Use to execute store procedure or sql script to insert, update or delete.

Declaration
Task<int> ExecuteSqlCommandAsync(string sql, IDictionary<string, object> parameters = null)
Parameters
Type Name Description
System.String sql

SQL script to execute on database.

IDictionary<System.String, System.Object> parameters

Key and value as parameter of the query.

Returns
Type Description
System.Threading.Tasks.Task<System.Int32>

Result of async execution.

ExecuteStrategyAsync(Action)

Executes the specified asynchronous operation.

Declaration
Task ExecuteStrategyAsync(Action action)
Parameters
Type Name Description
System.Action action

The strategy that will be used for the execution. A function that returns a started task.

Returns
Type Description
System.Threading.Tasks.Task

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

GetDbSet<TEntity>()

Method that sets up the entity to be used in context.

note

Only entities that implement the IModel interface can be configured in the context.

Declaration
DbSet<TEntity> GetDbSet<TEntity>()
    where TEntity : class, IModel
Returns
Type Description
DbSet<TEntity>

Entity used to query and save instances.

Type Parameters
Name Description
TEntity

The type of entity being operated on by this set.

SaveChanges()

Synchronous method that confirms the modifications made to entities within the context.

Declaration
int SaveChanges()
Returns
Type Description
System.Int32

The number of state entries written to the database.

SaveChangesAsync(CancellationToken)

Asynchronous method that confirms the modifications made to entities within the context.

Declaration
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken

Spreads the notification that transactions should be canceled.

Returns
Type Description
System.Threading.Tasks.Task<System.Int32>

A task that represents the asynchronous save operation. The task result contains the number of state entries written to the database.

SetAutoDetectChanges(Boolean)

Enable or disable the tracking from entities changes.

Declaration
void SetAutoDetectChanges(bool enable = true)
Parameters
Type Name Description
System.Boolean enable

True if enable auto detect change, otherwise, false.

SetDeleted<TEntity>(TEntity)

Method that sets up the entity to deleted in context.

note

Only entities that implement the IModel interface can be configured in the context with with deleted status.

Declaration
void SetDeleted<TEntity>(TEntity entity)
    where TEntity : class, IModel
Parameters
Type Name Description
TEntity entity

The modified entity.

Type Parameters
Name Description
TEntity

The type of entity being operated on by this set.

SetModified<TEntity>(TEntity)

Method that sets up the entity to modified in context.

note

Only entities that implement the IModel interface can be configured in the context with with modified status.

Declaration
void SetModified<TEntity>(TEntity entity)
    where TEntity : class, IModel
Parameters
Type Name Description
TEntity entity

The modified entity.

Type Parameters
Name Description
TEntity

The type of entity being operated on by this set.

SetTimeOut(Int32)

Set timeout to execute the commands into context instance.

Declaration
void SetTimeOut(int timeoutInSeconds = 180)
Parameters
Type Name Description
System.Int32 timeoutInSeconds

Value that represent in seconds the timeout.

UseNoLock()

Method for querying with nolock.

Declaration
IDbContextTransaction UseNoLock()
Returns
Type Description
IDbContextTransaction

A transaction against the database.

Back to top Generated by DocFX