/// <summary>
        /// Delete multiple records using a filter object.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="filterValue">The filter value.</param>
        /// <param name="filterOptions">The options.</param>
        public MultipleRowDbCommandBuilder <AbstractCommand, AbstractParameter> DeleteWithFilter(AbstractObjectName tableName, object filterValue, FilterOptions filterOptions = FilterOptions.None)
        {
            var table = DatabaseMetadata.GetTableOrView(tableName);

            if (!AuditRules.UseSoftDelete(table))
            {
                return(OnDeleteMany(tableName, filterValue, filterOptions));
            }

            return(OnUpdateMany(tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(filterValue, filterOptions));
        }
예제 #2
0
        /// <summary>
        /// Deletes multiple records using a where expression.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="whereClause">The where clause.</param>
        public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteWithFilter(SQLiteObjectName tableName, string whereClause)
        {
            var table = DatabaseMetadata.GetTableOrView(tableName);

            if (!AuditRules.UseSoftDelete(table))
            {
                return(new SQLiteDeleteMany(this, tableName, whereClause, null));
            }

            return(new SQLiteUpdateMany(this, tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(whereClause, null));
        }
예제 #3
0
        /// <summary>
        /// Deletes multiple records using a where expression.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="whereClause">The where clause.</param>
        /// <param name="argumentValue">The argument value for the where clause.</param>
        public MultipleRowDbCommandBuilder <OleDbCommand, OleDbParameter> DeleteWithFilter(SqlServerObjectName tableName, string whereClause, object argumentValue)
        {
            var table = DatabaseMetadata.GetTableOrView(tableName);

            if (!AuditRules.UseSoftDelete(table))
            {
                return(new OleDbSqlServerDeleteMany(this, tableName, whereClause, argumentValue));
            }

            return(new OleDbSqlServerUpdateMany(this, tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(whereClause, argumentValue));
        }
예제 #4
0
        /// <summary>
        /// Deletes multiple records using a filter object.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="filterValue">The filter value.</param>
        /// <param name="filterOptions">The options.</param>
        public MultipleRowDbCommandBuilder <OleDbCommand, OleDbParameter> DeleteWithFilter(SqlServerObjectName tableName, object filterValue, FilterOptions filterOptions = FilterOptions.None)
        {
            var table = DatabaseMetadata.GetTableOrView(tableName);

            if (!AuditRules.UseSoftDelete(table))
            {
                return(new OleDbSqlServerDeleteMany(this, tableName, filterValue, filterOptions));
            }

            return(new OleDbSqlServerUpdateMany(this, tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(filterValue, filterOptions));
        }
예제 #5
0
    MultipleRowDbCommandBuilder <AbstractCommand, AbstractParameter> IUpdateDeleteByKeyHelper <AbstractCommand, AbstractParameter, AbstractObjectName, AbstractDbType> .OnDeleteByKeyList <TKey>(AbstractObjectName tableName, IEnumerable <TKey> keys, DeleteOptions options)
    {
        var primaryKeys = DatabaseMetadata.GetTableOrView(tableName).PrimaryKeyColumns;

        if (primaryKeys.Count != 1)
        {
            throw new MappingException($"{nameof(DeleteByKeyList)} operation isn't allowed on {tableName} because it doesn't have a single primary key.");
        }

        var keyList        = keys.AsList();
        var columnMetadata = primaryKeys.Single();

        string where;
        if (keys.Count() > 1)
        {
            where = columnMetadata.SqlName + " IN (" + string.Join(", ", keyList.Select((s, i) => "?")) + ")";
        }
        else
        {
            where = columnMetadata.SqlName + " = ?";
        }

        var parameters = new List <OleDbParameter>();

        for (var i = 0; i < keyList.Count; i++)
        {
            var param = new OleDbParameter("@Param" + i, keyList[i]);
            if (columnMetadata.DbType.HasValue)
            {
                param.OleDbType = columnMetadata.DbType.Value;
            }
            parameters.Add(param);
        }

        var table = DatabaseMetadata.GetTableOrView(tableName);

        if (!AuditRules.UseSoftDelete(table))
        {
            return(new OleDbSqlServerDeleteSet(this, tableName, where, parameters, parameters.Count, options));
        }

        UpdateOptions effectiveOptions = UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected;

        if (options.HasFlag(DeleteOptions.UseKeyAttribute))
        {
            effectiveOptions = effectiveOptions | UpdateOptions.UseKeyAttribute;
        }

        return(new OleDbSqlServerUpdateSet(this, tableName, null, where, parameters, parameters.Count, effectiveOptions));
    }