Data/CafeLib.Data.Sources/SqlCommandProvider.cs
/// <summary>
/// Bulk delete of entity records.
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
/// <param name="connectionInfo">Connection info</param>
/// <param name="data">Collection of entity records</param>
/// <param name="token">Cancellation token</param>
/// <returns></returns>
Bulk delete of entity records.
Bulk delete of entity records .
public async Task<int> DeleteAsync<TEntity>(IConnectionInfo connectionInfo, IEnumerable<TEntity> data, CancellationToken token = default) where TEntity : class, IEntity
        {
            if (data == null) throw new ArgumentNullException(nameof(data));
            await using var connection = connectionInfo.GetConnection<T>();
            using var transaction = connection.BeginTransaction();
            try
            {
                var deleted = await connection.DeleteAllAsync(data, transaction: transaction, cancellationToken: token).ConfigureAwait(false);
                transaction.Commit();
                return deleted;
            }
            catch (Exception)
            {
                try
                {
                    transaction.Rollback();
                    throw;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
public async Task < int > DeleteAsync < TEntity > ( IConnectionInfo connectionInfo , IEnumerable < TEntity > data , CancellationToken token = default ) where TEntity : class , IEntity { if ( data == null ) throw new ArgumentNullException ( nameof ( data ) ) ; await using var connection = connectionInfo . GetConnection < T > ( ) ; using var transaction = connection . BeginTransaction ( ) ; try { var deleted = await connection . DeleteAllAsync ( data , transaction : transaction , cancellationToken : token ) . ConfigureAwait ( false ) ; transaction . Commit ( ) ; return deleted ; } catch ( Exception ) { try { transaction . Rollback ( ) ; throw ; } catch ( Exception ex ) { throw ex ; } } }
Bulk delete of entity records.
Bulk delete of entity records .
// ReSharper disable once PossibleIntendedRethrow
None
connectionInfo
IConnectionInfo
None
data
IEnumerable<TEntity>
Collection of entity records
Collection of entity records
token
CancellationToken
None
typeparam
None