Exemple #1
0
        /// <summary>
        /// Updates records from matching database recordset.
        /// </summary>
        /// <typeparam name="TSource">Entity type of source database recordset.</typeparam>
        /// <param name="source">The source matching database recordset.</param>
        /// <param name="columnMapper">Provides column mappings between source database recordset and this table.</param>
        /// <param name="keyMapper">Provides key mapping between source database recordset and this table.</param>
        /// <param name="ct">The async cancellation token.</param>
        /// <returns>Number of rows updated.</returns>
        public Task <int> UpdateAsync <TSource>(DbSet <TSource> source, Action <ColumnMapper, TSource, T> columnMapper, Func <TSource, T, KeyMapping> keyMapper, CancellationToken ct = default(CancellationToken))
            where TSource : class, IEntity, new()
        {
            Verify(source, nameof(source));
            var columnMappings = Verify(columnMapper, nameof(columnMapper), source._);
            var keyMapping     = Verify(keyMapper, nameof(keyMapper), source._);

            return(DbTableUpdate <T> .ExecuteAsync(this, source, columnMappings, keyMapping.GetColumnMappings(), ct));
        }
Exemple #2
0
        /// <summary>
        /// Updates from matching row in DataSet.
        /// </summary>
        /// <typeparam name="TSource">Entity type of source DataSet.</typeparam>
        /// <param name="source">The source DataSet.</param>
        /// <param name="rowIndex">The row index in DataSet.</param>
        /// <param name="columnMapper">Provides column mappings between source DataSet and this table.</param>
        /// <param name="keyMapper">Provides key mapping between source DataSet and this table.</param>
        /// <param name="ct">The async cancellation token.</param>
        /// <returns>Number of rows updated.</returns>
        public Task <int> UpdateAsync <TSource>(DataSet <TSource> source, int rowIndex, Action <ColumnMapper, TSource, T> columnMapper, Func <TSource, T, KeyMapping> keyMapper, CancellationToken ct = default(CancellationToken))
            where TSource : Model, new()
        {
            Verify(source, nameof(source), rowIndex, nameof(rowIndex));
            var columnMappings = Verify(columnMapper, nameof(columnMapper), source._);
            var join           = Verify(keyMapper, nameof(keyMapper), source._).GetColumnMappings();

            return(DbTableUpdate <T> .ExecuteAsync(this, source, rowIndex, columnMappings, join, ct));
        }
Exemple #3
0
        /// <summary>
        /// Updates records in this table from matching DataSet.
        /// </summary>
        /// <typeparam name="TSource">Entity type of source DataSet.</typeparam>
        /// <param name="source">The source DataSet.</param>
        /// <param name="columnMapper">Provides column mappings between source DataSet and this table.</param>
        /// <param name="keyMapper">Provides key mapping between source DataSet and this table.</param>
        /// <param name="ct">The async cancellation token.</param>
        /// <returns>Number of rows updated.</returns>
        public Task <int> UpdateAsync <TSource>(DataSet <TSource> source, Action <ColumnMapper, TSource, T> columnMapper, Func <TSource, T, KeyMapping> keyMapper, CancellationToken ct = default(CancellationToken))
            where TSource : class, IEntity, new()
        {
            Verify(source, nameof(source));
            if (source.Count == 1)
            {
                return(UpdateAsync(source, 0, columnMapper, keyMapper, ct));
            }

            Verify(columnMapper, nameof(columnMapper));
            var targetKey = Verify(keyMapper, nameof(keyMapper), source._).TargetKey;

            return(DbTableUpdate <T> .ExecuteAsync(this, source, columnMapper, targetKey, ct));
        }
Exemple #4
0
        /// <summary>
        /// Updates subset of records with specified values.
        /// </summary>
        /// <param name="columnMapper">Provides column mappings between value and column in this table.</param>
        /// <param name="where">The condition to filter the records.</param>
        /// <param name="ct">The async cancellation token.</param>
        /// <returns>Number of rows updated.</returns>
        public Task <int> UpdateAsync(Action <ColumnMapper, T> columnMapper, Func <T, _Boolean> where, CancellationToken ct = default(CancellationToken))
        {
            var columnMappings = Verify(columnMapper, nameof(columnMapper));

            return(DbTableUpdate <T> .ExecuteAsync(this, columnMappings, where, ct));
        }