Class DataContextExtensions
Extension methods for IDataContext.
Inheritance
Inherited Members
Namespace: Kephas.Data
Assembly: Kephas.Data.dll
Syntax
public static class DataContextExtensions
Methods
| Improve this Doc View SourceBulkDeleteAsync(IDataContext, IBulkDeleteContext, CancellationToken)
Deletes the entities matching the provided criteria and returns the number of affected entities asynchronously.
Declaration
public static Task<long> BulkDeleteAsync(this IDataContext dataContext, IBulkDeleteContext bulkDeleteContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IBulkDeleteContext | bulkDeleteContext | The bulk delete context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int64> | A promise of the number of affected entities. |
Remarks
The entities are physically removed from the database without invoking any behavior.
BulkDeleteAsync<T>(IDataContext, Expression<Func<T, Boolean>>, Boolean, CancellationToken)
Deletes the entities matching the provided criteria and returns the number of affected entities asynchronously.
Declaration
public static Task<long> BulkDeleteAsync<T>(this IDataContext dataContext, Expression<Func<T, bool>> criteria, bool throwIfNotFound = true, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Linq.Expressions.Expression<System.Func<T, System.Boolean>> | criteria | The matching criteria for entities to delete. |
System.Boolean | throwIfNotFound | Optional. |
System.Threading.CancellationToken | cancellationToken | Optional. The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int64> | A promise of the number of affected entities. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
Remarks
The entities are physically removed from the database without invoking any behavior.
BulkUpdateAsync(IDataContext, IBulkUpdateContext, CancellationToken)
Updates the entities matching the provided criteria and returns the number of affected entities asynchronously.
Declaration
public static Task<long> BulkUpdateAsync(this IDataContext dataContext, IBulkUpdateContext bulkUpdateContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IBulkUpdateContext | bulkUpdateContext | The bulk update context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int64> | A promise of the number of affected entities. |
Remarks
The entities are physically updated in the database without invoking any behavior.
BulkUpdateAsync<T>(IDataContext, Expression<Func<T, Boolean>>, Object, Boolean, CancellationToken)
Updates the entities matching the provided criteria and returns the number of affected entities asynchronously.
Declaration
public static Task<long> BulkUpdateAsync<T>(this IDataContext dataContext, Expression<Func<T, bool>> criteria, object values, bool throwIfNotFound = true, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Linq.Expressions.Expression<System.Func<T, System.Boolean>> | criteria | The matching criteria for entities to delete. |
System.Object | values | The values. |
System.Boolean | throwIfNotFound | Optional. |
System.Threading.CancellationToken | cancellationToken | Optional. The cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Int64> | A promise of the number of affected entities. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
Remarks
The entities are physically updated in the database without invoking any behavior.
CreateAsync(IDataContext, ICreateEntityContext, CancellationToken)
Creates asynchronously a new entity of the provided type and returns it.
Declaration
public static Task<object> CreateAsync(this IDataContext dataContext, ICreateEntityContext operationContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
ICreateEntityContext | operationContext | Context for the create entity operation (optional). |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A promise of the created entity. |
CreateAsync(IDataContext, Type, CancellationToken)
Creates asynchronously a new entity of the provided type and returns it.
Declaration
public static Task<object> CreateAsync(this IDataContext dataContext, Type entityType, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Type | entityType | Type of the entity to create. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A promise of the created entity. |
CreateAsync<T>(IDataContext, ICreateEntityContext, CancellationToken)
Creates asynchronously a new entity of the provided type and returns it.
Declaration
public static Task<T> CreateAsync<T>(this IDataContext dataContext, ICreateEntityContext operationContext, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
ICreateEntityContext | operationContext | Context for the create entity operation (optional). |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A promise of the created entity. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity to create. |
CreateAsync<T>(IDataContext, CancellationToken)
Creates asynchronously a new entity of the provided type and returns it.
Declaration
public static Task<T> CreateAsync<T>(this IDataContext dataContext, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A promise of the created entity. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity to create. |
CreateCommand<TCommand>(IDataContext)
Creates the command with the provided type.
Declaration
public static TCommand CreateCommand<TCommand>(this IDataContext dataContext)
where TCommand : IDataCommand
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
Returns
Type | Description |
---|---|
TCommand | The new command. |
Type Parameters
Name | Description |
---|---|
TCommand | The type of the command to be created. |
Delete<T>(IDataContext, T[])
Marks the provided entity for deletion in the data context.
Declaration
public static void Delete<T>(this IDataContext dataContext, params T[] entities)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
T[] | entities | The entities to delete. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
Delete<T>(IDataContext, IEnumerable<T>)
Marks the provided entities for deletion in the data context.
Declaration
public static void Delete<T>(this IDataContext dataContext, IEnumerable<T> entities)
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Collections.Generic.IEnumerable<T> | entities | The entities to delete. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
Detach(IDataContext, Object)
Detaches the entity from the data context.
Declaration
public static IEntityEntry Detach(this IDataContext dataContext, object entity)
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Object | entity | The entity. |
Returns
Type | Description |
---|---|
IEntityEntry | The entity extended information. |
DiscardChanges(IDataContext)
Discards the changes in the data context.
Declaration
public static IDataCommandResult DiscardChanges(this IDataContext dataContext)
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
Returns
Type | Description |
---|---|
IDataCommandResult | The result of discarding the changes. |
ExecuteAsync(IDataContext, IExecuteContext, CancellationToken)
Executes the provided command in the data context.
Declaration
public static Task<object> ExecuteAsync(this IDataContext dataContext, IExecuteContext executeContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IExecuteContext | executeContext | Context for the execution. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A promise of the command execution result. |
Exceptions
Type | Condition |
---|---|
DataException | Thrown when a Data error condition occurs. |
ExecuteAsync(IDataContext, String, CancellationToken)
Executes the provided command in the data context.
Declaration
public static Task<object> ExecuteAsync(this IDataContext dataContext, string commandText, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.String | commandText | The command text. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A promise of the command execution result. |
FindAsync(IDataContext, IFindContext, CancellationToken)
Searches for the entity with the provided ID and returns it asynchronously.
Declaration
public static Task<object> FindAsync(this IDataContext dataContext, IFindContext findContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IFindContext | findContext | Context for the find operation. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A promise of the found entity. |
FindAsync(IDataContext, Type, Object, Boolean, CancellationToken)
Searches for the entity with the provided ID and returns it asynchronously.
Declaration
public static Task<object> FindAsync(this IDataContext dataContext, Type entityType, object id, bool throwIfNotFound = true, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Type | entityType | Type of the entity. |
System.Object | id | The entity ID. |
System.Boolean | throwIfNotFound | If |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A promise of the found entity. |
FindAsync<T>(IDataContext, IFindContext, CancellationToken)
Searches for the entity with the provided ID and returns it asynchronously.
Declaration
public static Task<T> FindAsync<T>(this IDataContext dataContext, IFindContext findContext, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IFindContext | findContext | Context for the find operation. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A promise of the found entity. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
FindAsync<T>(IDataContext, Object, Boolean, CancellationToken)
Searches for the entity with the provided ID and returns it asynchronously.
Declaration
public static Task<T> FindAsync<T>(this IDataContext dataContext, object id, bool throwIfNotFound = true, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Object | id | The entity ID. |
System.Boolean | throwIfNotFound | If |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A promise of the found entity. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
FindOneAsync(IDataContext, IFindOneContext, CancellationToken)
Searches for the first entity matching the provided criteria and returns it asynchronously.
Declaration
public static Task<object> FindOneAsync(this IDataContext dataContext, IFindOneContext findContext, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IFindOneContext | findContext | The find context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | A promise of the found entity. |
FindOneAsync<T>(IDataContext, IFindOneContext, CancellationToken)
Searches for the first entity matching the provided criteria and returns it asynchronously.
Declaration
public static Task<T> FindOneAsync<T>(this IDataContext dataContext, IFindOneContext findContext, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IFindOneContext | findContext | The find context. |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A promise of the found entity. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
FindOneAsync<T>(IDataContext, Expression<Func<T, Boolean>>, Boolean, CancellationToken)
Searches for the first entity matching the provided criteria and returns it asynchronously.
Declaration
public static Task<T> FindOneAsync<T>(this IDataContext dataContext, Expression<Func<T, bool>> criteria, bool throwIfNotFound = true, CancellationToken cancellationToken = default(CancellationToken))
where T : class
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
System.Linq.Expressions.Expression<System.Func<T, System.Boolean>> | criteria | The criteria. |
System.Boolean | throwIfNotFound |
|
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | A promise of the found entity. |
Type Parameters
Name | Description |
---|---|
T | The type of the entity. |
PersistChangesAsync(IDataContext, IPersistChangesContext, CancellationToken)
Persists the changes in the dataContext asynchronously.
Declaration
public static Task<IDataCommandResult> PersistChangesAsync(this IDataContext dataContext, IPersistChangesContext persistContext = null, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
IDataContext | dataContext | The data context. |
IPersistChangesContext | persistContext | The context for persisting changes (optional). |
System.Threading.CancellationToken | cancellationToken | The cancellation token (optional). |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IDataCommandResult> | A promise of the persist result. |