private DbKeysInt<T> CreateBulkDeleteKeys<KeyType>() { if (Info.DeleteKeyColumns.Count == 0) { // NoDeletesAttribute return (connection, keys, transaction, commandTimeout) => { return 0; }; } string deleteCmd = DeleteCmd(); string keyName = EqualityColumns[0].ColumnName; return (connection, keys, transaction, commandTimeout) => { int count = 0; string bulkDeleteCmd = $"{deleteCmd}WHERE \t{keyName} in @Keys"; foreach (IEnumerable<KeyType> Keys in ExtraUtil.Partition(keys.Select(k => (KeyType) k), 2000)) { try { int deleted = connection.Execute(bulkDeleteCmd, new { Keys }, transaction, commandTimeout); count += deleted; } catch (Exception ex) { throw new InvalidOperationException(ex.Message + "\n" + bulkDeleteCmd); } } return count; }; }
private DbKeysList<T> CreateBulkGetKeys<KeyType>() { string paramsSelectFromTableBulk = ParamsSelectFromTableBulk(); string keyName = EqualityColumns[0].ColumnName; return (connection, keys, transaction, commandTimeout) => { List<T> result = new List<T>(); string bulkGetKeysQuery = $"SELECT {paramsSelectFromTableBulk}WHERE \t{keyName} in @Keys"; foreach (IEnumerable<KeyType> Keys in ExtraUtil.Partition(keys.Select(k => (KeyType) k), 2000)) { try { IEnumerable<T> list = connection.Query<T>(bulkGetKeysQuery, new { Keys }, transaction, true, commandTimeout); result.AddRange(list); } catch (Exception ex) { throw new InvalidOperationException(ex.Message + "\n" + bulkGetKeysQuery); } } return result; }; }