| | | 1 | | #region Usings |
| | | 2 | | using ZhEaIsNsAaBn.Infrastructure.SqlServer; |
| | | 3 | | using static ZhEaIsNsAaBn.DbSeeder.SqlServer.SqlServerSeedSql; |
| | | 4 | | #endregion |
| | | 5 | | |
| | | 6 | | namespace ZhEaIsNsAaBn.DbSeeder.SqlServer; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// SQL Server implementation of <see cref="ISeedDatabaseProvider"/> (plan §7): <c>sp_getapplock</c> session lock, bulk |
| | | 10 | | /// <c>#seed_n</c> then <c>UPDATE</c> + <c>INSERT … WHERE NOT EXISTS</c> (no <c>MERGE</c>), set-based deletes, foreign-k |
| | | 11 | | /// <c>sys.foreign_keys</c>. Stateless; runs on the context's connection and transaction. Errors are classified by |
| | | 12 | | /// <see cref="SqlServerDbErrorClassifier"/>. |
| | | 13 | | /// </summary> |
| | | 14 | | internal sealed partial class SqlServerSeedDatabaseProvider : ISeedDatabaseProvider |
| | | 15 | | { |
| | | 16 | | private static long _tempTables; |
| | | 17 | | |
| | | 18 | | |
| | 14 | 19 | | private SqlServerSeedDatabaseProvider() { } |
| | | 20 | | |
| | | 21 | | |
| | 7 | 22 | | public static SqlServerSeedDatabaseProvider Instance { get; } = new(); |
| | | 23 | | |
| | | 24 | | |
| | | 25 | | public async Task EnsureTablesAsync( DbContext dbContext, bool async, CancellationToken cancellationToken ) |
| | | 26 | | { |
| | 332 | 27 | | using var command = Command( dbContext, CreateHistory + "\n" + CreateAudit ); |
| | | 28 | | |
| | 332 | 29 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | 332 | 30 | | } |
| | | 31 | | |
| | | 32 | | public async Task<bool> AcquireLockAsync( DbContext dbContext, TimeSpan timeout, bool async, CancellationToken cance |
| | | 33 | | { |
| | 321 | 34 | | var milliseconds = timeout < TimeSpan.Zero ? -1 : (int) Math.Min( timeout.TotalMilliseconds, int.MaxValue ); |
| | | 35 | | |
| | 321 | 36 | | using var command = Command( dbContext, AcquireLock, Parameter( "@TimeoutMs", milliseconds ) ); |
| | | 37 | | |
| | | 38 | | // The command must outlive the lock wait. |
| | 321 | 39 | | command.CommandTimeout = milliseconds < 0 ? 0 : command.CommandTimeout + (int) Math.Ceiling( milliseconds / 1000 |
| | | 40 | | |
| | | 41 | | |
| | 321 | 42 | | var result = System.Convert.ToInt32( await ScalarAsync( command, async, cancellationToken ).ConfigureAwait( fals |
| | | 43 | | |
| | | 44 | | // 0 / 1 granted, -1 timeout; -2 cancelled, -3 deadlock victim, -999 parameter / call error. |
| | 321 | 45 | | return result switch |
| | 321 | 46 | | { |
| | 317 | 47 | | >= 0 => true, |
| | 4 | 48 | | -1 => false, |
| | 0 | 49 | | _ => throw new InvalidOperationException( $"sp_getapplock returned {result}." ) |
| | 321 | 50 | | }; |
| | 321 | 51 | | } |
| | | 52 | | |
| | | 53 | | public async Task ReleaseLockAsync( DbContext dbContext, bool async, CancellationToken cancellationToken ) |
| | | 54 | | { |
| | 317 | 55 | | using var command = Command( dbContext, ReleaseLock ); |
| | | 56 | | |
| | 317 | 57 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | 317 | 58 | | } |
| | | 59 | | |
| | | 60 | | public async Task<IReadOnlyList<SeedHistoryRow>> ReadHistoryAsync( DbContext dbContext, string contextKey, bool asyn |
| | | 61 | | { |
| | 341 | 62 | | using ( var exists = Command( dbContext, HistoryExists ) ) |
| | | 63 | | { |
| | 344 | 64 | | if ( System.Convert.ToInt32( await ScalarAsync( exists, async, cancellationToken ).ConfigureAwait( false ), |
| | 338 | 65 | | } |
| | | 66 | | |
| | | 67 | | |
| | 338 | 68 | | using var command = Command( dbContext, ReadHistory, Parameter( "@ContextKey", contextKey ) ); |
| | 338 | 69 | | using var reader = async ? await command.ExecuteReaderAsync( cancellationToken ).ConfigureAwait( false ) : comm |
| | 338 | 70 | | var rows = new List<SeedHistoryRow>(); |
| | | 71 | | |
| | 675 | 72 | | while ( async ? await reader.ReadAsync( cancellationToken ).ConfigureAwait( false ) : reader.Read() ) |
| | | 73 | | { |
| | 337 | 74 | | rows.Add( new SeedHistoryRow |
| | 337 | 75 | | { |
| | 337 | 76 | | MigrationId = reader.GetString( 0 ), |
| | 337 | 77 | | ContextKey = reader.GetString( 1 ), |
| | 337 | 78 | | Checksum = reader.GetString( 2 ), |
| | 337 | 79 | | AppliedOn = reader.GetDateTime( 3 ), |
| | 337 | 80 | | ProductVersion = reader.GetString( 4 ) |
| | 337 | 81 | | } ); |
| | | 82 | | } |
| | | 83 | | |
| | | 84 | | |
| | 338 | 85 | | return rows; |
| | 341 | 86 | | } |
| | | 87 | | |
| | | 88 | | public async Task<SeedWriteCounts> UpsertAsync( DbContext dbContext, SeedTableWrite write, bool async, CancellationT |
| | | 89 | | { |
| | 1146 | 90 | | ArgumentNullException.ThrowIfNull( write ); |
| | | 91 | | |
| | 1146 | 92 | | if ( write.Rows.Count == 0 ) { return default; } |
| | | 93 | | |
| | | 94 | | |
| | 1146 | 95 | | var (temp, identity) = await LoadAsync( dbContext, write.Table, write.Columns, write.Rows, async, cancellationTo |
| | 1146 | 96 | | var updated = Output( "@Updated" ); |
| | 1146 | 97 | | var inserted = Output( "@Inserted" ); |
| | | 98 | | |
| | 1146 | 99 | | using var command = Command( dbContext, |
| | 1146 | 100 | | Upsert( write, temp, identity ), |
| | 1146 | 101 | | [ updated, inserted, ..Values( "@u", write.UpdateValues ), ..Values( "@i", write.In |
| | | 102 | | |
| | 1146 | 103 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | | 104 | | |
| | | 105 | | |
| | 1142 | 106 | | return new SeedWriteCounts( (int) inserted.Value, (int) updated.Value ); |
| | 1142 | 107 | | } |
| | | 108 | | |
| | | 109 | | public async Task<int> DeleteAsync( DbContext dbContext, SeedTableKeys keys, bool async, CancellationToken cancellat |
| | | 110 | | { |
| | 99 | 111 | | ArgumentNullException.ThrowIfNull( keys ); |
| | | 112 | | |
| | 99 | 113 | | if ( keys.Keys.Count == 0 ) { return 0; } |
| | | 114 | | |
| | | 115 | | |
| | 99 | 116 | | var (temp, _) = await LoadAsync( dbContext, keys.Table, keys.Table.MatchColumns, keys.Keys, async, cancellationT |
| | 99 | 117 | | var count = Output( "@Count" ); |
| | | 118 | | |
| | 99 | 119 | | using var command = Command( dbContext, Delete( keys.Table, temp ), count ); |
| | | 120 | | |
| | 99 | 121 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | | 122 | | |
| | 96 | 123 | | return (int) count.Value; |
| | 96 | 124 | | } |
| | | 125 | | |
| | | 126 | | public Task<int> SoftDeleteAsync( DbContext dbContext, SeedTableKeys keys, IReadOnlyList<SeedColumnValue> values, bo |
| | 165 | 127 | | => SetFlaggedAsync( dbContext, keys, values, flagged: false, async, cancellationToken ); |
| | | 128 | | |
| | | 129 | | public Task<int> RestoreAsync( DbContext dbContext, SeedTableKeys keys, IReadOnlyList<SeedColumnValue> values, bool |
| | 62 | 130 | | => SetFlaggedAsync( dbContext, keys, values, flagged: true, async, cancellationToken ); |
| | | 131 | | |
| | | 132 | | public async Task DeleteHistoryAsync( DbContext dbContext, string migrationId, string contextKey, bool async, Cancel |
| | | 133 | | { |
| | 96 | 134 | | using var command = Command( dbContext, DeleteHistory, Parameter( "@MigrationId", migrationId ), Parameter( "@Co |
| | | 135 | | |
| | 96 | 136 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | 96 | 137 | | } |
| | | 138 | | |
| | | 139 | | private static async Task<int> SetFlaggedAsync( DbContext dbContext, SeedTableKeys keys, IReadOnlyList<SeedColumnVal |
| | | 140 | | { |
| | 227 | 141 | | ArgumentNullException.ThrowIfNull( keys ); |
| | 227 | 142 | | ArgumentNullException.ThrowIfNull( values ); |
| | | 143 | | |
| | 227 | 144 | | if ( keys.Table.SoftDeleteFlag is null ) { throw new InvalidOperationException( $"{keys.Table.DisplayName} has n |
| | | 145 | | |
| | 227 | 146 | | if ( keys.Keys.Count == 0 ) { return 0; } |
| | | 147 | | |
| | | 148 | | |
| | 227 | 149 | | var (temp, _) = await LoadAsync( dbContext, keys.Table, keys.Table.MatchColumns, keys.Keys, async, cancellationT |
| | 227 | 150 | | var count = Output( "@Count" ); |
| | | 151 | | |
| | 227 | 152 | | using var command = Command( dbContext, SetFlagged( keys.Table, temp, values, flagged ), [ count, ..Values( "@v" |
| | | 153 | | |
| | 227 | 154 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | | 155 | | |
| | 227 | 156 | | return (int) count.Value; |
| | 227 | 157 | | } |
| | | 158 | | |
| | | 159 | | public async Task<IReadOnlyList<SeedBlocker>> CountReferencesAsync( DbContext dbContext, SeedTableKeys keys, bool as |
| | | 160 | | { |
| | 150 | 161 | | ArgumentNullException.ThrowIfNull( keys ); |
| | | 162 | | |
| | 150 | 163 | | if ( keys.Keys.Count == 0 ) { return []; } |
| | | 164 | | |
| | | 165 | | |
| | 150 | 166 | | var foreignKeys = await ReferencingKeysAsync( dbContext, Table( keys.Table ), async, cancellationToken ).Configu |
| | | 167 | | |
| | 213 | 168 | | if ( foreignKeys.Count == 0 ) { return []; } |
| | | 169 | | |
| | | 170 | | |
| | 87 | 171 | | var (temp, _) = await LoadAsync( dbContext, keys.Table, keys.Table.MatchColumns, keys.Keys, async, cancellation |
| | 87 | 172 | | var blockers = new List<SeedBlocker>(); |
| | | 173 | | |
| | 348 | 174 | | foreach ( var foreignKey in foreignKeys ) |
| | | 175 | | { |
| | 87 | 176 | | var referencing = $"{Quote( foreignKey.Schema )}.{Quote( foreignKey.Table )}"; |
| | 87 | 177 | | var isSelf = string.Equals( foreignKey.Table, keys.Table.Name, StringComparison.Ordinal ) |
| | 87 | 178 | | && string.Equals( foreignKey.Schema, keys.Table.Schema ?? foreignKey.Schema, StringComparison |
| | | 179 | | |
| | 87 | 180 | | using var command = Command( dbContext, CountReferences( keys.Table, temp, referencing, foreignKey.Pairs, is |
| | | 181 | | |
| | 87 | 182 | | var count = System.Convert.ToInt32( await ScalarAsync( command, async, cancellationToken ).ConfigureAwait( f |
| | | 183 | | |
| | 144 | 184 | | if ( count > 0 ) { blockers.Add( new SeedBlocker( $"{foreignKey.Schema}.{foreignKey.Table}", string.Join( ", |
| | 87 | 185 | | } |
| | | 186 | | |
| | | 187 | | |
| | 261 | 188 | | using ( var drop = Command( dbContext, $"DROP TABLE {temp};" ) ) { await NonQueryAsync( drop, async, cancellatio |
| | | 189 | | |
| | 87 | 190 | | return blockers; |
| | 150 | 191 | | } |
| | | 192 | | |
| | | 193 | | public async Task WriteHistoryAsync( DbContext dbContext, SeedHistoryRow row, bool async, CancellationToken cancella |
| | | 194 | | { |
| | 281 | 195 | | ArgumentNullException.ThrowIfNull( row ); |
| | | 196 | | |
| | 281 | 197 | | using var command = Command( dbContext, |
| | 281 | 198 | | InsertHistory, |
| | 281 | 199 | | Parameter( "@MigrationId", row.MigrationId ), |
| | 281 | 200 | | Parameter( "@ContextKey", row.ContextKey ), |
| | 281 | 201 | | Parameter( "@Checksum", row.Checksum ), |
| | 281 | 202 | | Parameter( "@AppliedOn", row.AppliedOn ), |
| | 281 | 203 | | Parameter( "@ProductVersion", row.ProductVersion ) ); |
| | | 204 | | |
| | 281 | 205 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | 281 | 206 | | } |
| | | 207 | | |
| | | 208 | | public async Task WriteAuditAsync( DbContext dbContext, SeedAuditRow row, bool async, CancellationToken cancellation |
| | | 209 | | { |
| | 327 | 210 | | ArgumentNullException.ThrowIfNull( row ); |
| | | 211 | | |
| | 327 | 212 | | using var command = Command( dbContext, |
| | 327 | 213 | | InsertAudit, |
| | 327 | 214 | | Parameter( "@MigrationId", row.MigrationId ), |
| | 327 | 215 | | Parameter( "@ContextKey", row.ContextKey ), |
| | 327 | 216 | | Parameter( "@Operation", row.Operation ), |
| | 327 | 217 | | Parameter( "@StartedOn", row.StartedOn ), |
| | 327 | 218 | | Parameter( "@FinishedOn", row.FinishedOn ), |
| | 327 | 219 | | Parameter( "@Succeeded", row.Succeeded ), |
| | 327 | 220 | | Parameter( "@ErrorCode", row.ErrorCode ), |
| | 327 | 221 | | Parameter( "@RowsInserted", row.RowsInserted ), |
| | 327 | 222 | | Parameter( "@RowsUpdated", row.RowsUpdated ), |
| | 327 | 223 | | Parameter( "@RowsDeleted", row.RowsDeleted ), |
| | 327 | 224 | | Parameter( "@OsUser", Truncate( row.OsUser ) ), |
| | 327 | 225 | | Parameter( "@MachineName", Truncate( row.MachineName ) ), |
| | 327 | 226 | | Parameter( "@ToolVersion", row.ToolVersion ), |
| | 327 | 227 | | Parameter( "@Details", row.Details ) ); |
| | | 228 | | |
| | 327 | 229 | | await NonQueryAsync( command, async, cancellationToken ).ConfigureAwait( false ); |
| | 327 | 230 | | } |
| | | 231 | | |
| | 7 | 232 | | public Error? Classify( Exception exception ) => SqlServerDbErrorClassifier.Instance.Classify( exception ); |
| | | 233 | | |
| | | 234 | | |
| | | 235 | | // ---- helpers ---- |
| | | 236 | | |
| | | 237 | | /// Creates <c>#seed_n</c> for <paramref name="columns"/> (collations from the target table) and bulk-copies the row |
| | | 238 | | /// <returns>The temp table name and the target's identity columns.</returns> |
| | | 239 | | private static async Task<(string Temp, IReadOnlySet<string> Identity)> LoadAsync( |
| | | 240 | | DbContext dbContext, |
| | | 241 | | SeedTable table, |
| | | 242 | | IReadOnlyList<SeedColumn> columns, |
| | | 243 | | IReadOnlyList<IReadOnlyList<object?>> rows, |
| | | 244 | | bool async, |
| | | 245 | | CancellationToken cancellationToken |
| | | 246 | | ) |
| | | 247 | | { |
| | 1595 | 248 | | var (collations, identity) = await TableColumnsAsync( dbContext, table, async, cancellationToken ).ConfigureAwai |
| | 1595 | 249 | | var temp = $"#seed_{Interlocked.Increment( ref _tempTables ).ToString( CultureInfo.InvariantCu |
| | | 250 | | |
| | 4785 | 251 | | using ( var create = Command( dbContext, CreateTemp( temp, columns, collations ) ) ) { await NonQueryAsync( crea |
| | | 252 | | |
| | | 253 | | |
| | 1595 | 254 | | using var data = new DataTable { Locale = CultureInfo.InvariantCulture }; |
| | | 255 | | |
| | 15355 | 256 | | foreach ( var column in columns ) { data.Columns.Add( column.ColumnName, Nullable.GetUnderlyingType( column.Prov |
| | | 257 | | |
| | 10270 | 258 | | foreach ( var row in rows ) { data.Rows.Add( row.Select( v => v ?? DBNull.Value ).ToArray() ); } |
| | | 259 | | |
| | | 260 | | |
| | 1595 | 261 | | using var bulk = new SqlBulkCopy( Connection( dbContext ), SqlBulkCopyOptions.Default, Transaction( dbContext ) |
| | 1595 | 262 | | { |
| | 1595 | 263 | | DestinationTableName = temp, |
| | 1595 | 264 | | BulkCopyTimeout = dbContext.Database.GetCommandTimeout() ?? 30 |
| | 1595 | 265 | | }; |
| | | 266 | | |
| | 15355 | 267 | | foreach ( var column in columns ) { bulk.ColumnMappings.Add( column.ColumnName, column.ColumnName ); } |
| | | 268 | | |
| | | 269 | | |
| | 3110 | 270 | | if ( async ) { await bulk.WriteToServerAsync( data, cancellationToken ).ConfigureAwait( false ); } |
| | 80 | 271 | | else { bulk.WriteToServer( data ); } |
| | | 272 | | |
| | 1595 | 273 | | return ( temp, identity ); |
| | 1595 | 274 | | } |
| | | 275 | | |
| | | 276 | | private static async Task<(IReadOnlyDictionary<string, string> Collations, IReadOnlySet<string> Identity)> TableColu |
| | | 277 | | DbContext dbContext, |
| | | 278 | | SeedTable table, |
| | | 279 | | bool async, |
| | | 280 | | CancellationToken cancellationToken |
| | | 281 | | ) |
| | | 282 | | { |
| | 1595 | 283 | | using var command = Command( dbContext, TableColumns, Parameter( "@Table", Table( table ) ) ); |
| | 1595 | 284 | | using var reader = async ? await command.ExecuteReaderAsync( cancellationToken ).ConfigureAwait( false ) : c |
| | 1595 | 285 | | var collations = new Dictionary<string, string>( StringComparer.Ordinal ); |
| | 1595 | 286 | | var identity = new HashSet<string>( StringComparer.Ordinal ); |
| | | 287 | | |
| | 13698 | 288 | | while ( async ? await reader.ReadAsync( cancellationToken ).ConfigureAwait( false ) : reader.Read() ) |
| | | 289 | | { |
| | 17135 | 290 | | if ( !reader.IsDBNull( 1 ) ) { collations[ reader.GetString( 0 ) ] = reader.GetString( 1 ); } |
| | | 291 | | |
| | 12382 | 292 | | if ( reader.GetBoolean( 2 ) ) { identity.Add( reader.GetString( 0 ) ); } |
| | | 293 | | } |
| | | 294 | | |
| | | 295 | | |
| | 1595 | 296 | | return ( collations, identity ); |
| | 1595 | 297 | | } |
| | | 298 | | |
| | | 299 | | private static async Task<IReadOnlyList<(string Schema, string Table, IReadOnlyList<(string Column, string Reference |
| | | 300 | | DbContext dbContext, |
| | | 301 | | string quotedTable, |
| | | 302 | | bool async, |
| | | 303 | | CancellationToken cancellationToken |
| | | 304 | | ) |
| | | 305 | | { |
| | 258 | 306 | | using var command = Command( dbContext, ReferencingKeys, Parameter( "@Table", quotedTable ) ); |
| | 258 | 307 | | using var reader = async ? await command.ExecuteReaderAsync( cancellationToken ).ConfigureAwait( false ) : comm |
| | 258 | 308 | | var keys = new List<(int Id, string Schema, string Table, List<(string, string)> Pairs)>(); |
| | | 309 | | |
| | 417 | 310 | | while ( async ? await reader.ReadAsync( cancellationToken ).ConfigureAwait( false ) : reader.Read() ) |
| | | 311 | | { |
| | 159 | 312 | | var id = reader.GetInt32( 0 ); |
| | | 313 | | |
| | 318 | 314 | | if ( keys.Count == 0 || keys[ ^1 ].Id != id ) { keys.Add( ( id, reader.GetString( 1 ), reader.GetString( 2 ) |
| | | 315 | | |
| | 159 | 316 | | keys[ ^1 ].Pairs.Add( ( reader.GetString( 3 ), reader.GetString( 4 ) ) ); |
| | | 317 | | } |
| | | 318 | | |
| | | 319 | | |
| | 258 | 320 | | return keys.Select( k => (k.Schema, k.Table, (IReadOnlyList<(string, string)>) k.Pairs) ).ToList(); |
| | 258 | 321 | | } |
| | | 322 | | |
| | | 323 | | private static SqlConnection Connection( DbContext dbContext ) |
| | 9462 | 324 | | => dbContext.Database.GetDbConnection() as SqlConnection |
| | 9462 | 325 | | ?? throw new InvalidOperationException( "ZhEaIsNsAaBn.DbSeeder.SqlServer needs a SQL Server context (UseSqlServe |
| | | 326 | | |
| | 9462 | 327 | | private static SqlTransaction? Transaction( DbContext dbContext ) => dbContext.Database.CurrentTransaction?.GetDbTra |
| | | 328 | | |
| | | 329 | | [ System.Diagnostics.CodeAnalysis.SuppressMessage( "Security", "CA2100:Review SQL queries for security vulnerabiliti |
| | | 330 | | Justification = "SQL is built by SqlServerSeedSql from EF / datab |
| | | 331 | | private static SqlCommand Command( DbContext dbContext, string sql, params SqlParameter[] parameters ) |
| | | 332 | | { |
| | 7867 | 333 | | var command = Connection( dbContext ).CreateCommand(); |
| | | 334 | | |
| | 7867 | 335 | | command.CommandText = sql; |
| | 7867 | 336 | | command.Transaction = Transaction( dbContext ); |
| | 7867 | 337 | | command.CommandTimeout = dbContext.Database.GetCommandTimeout() ?? 30; |
| | 7867 | 338 | | command.Parameters.AddRange( parameters ); |
| | | 339 | | |
| | 7867 | 340 | | return command; |
| | | 341 | | } |
| | | 342 | | |
| | | 343 | | private static async Task NonQueryAsync( SqlCommand command, bool async, CancellationToken cancellationToken ) |
| | | 344 | | { |
| | 9154 | 345 | | if ( async ) { await command.ExecuteNonQueryAsync( cancellationToken ).ConfigureAwait( false ); } |
| | 220 | 346 | | else { command.ExecuteNonQuery(); } |
| | 4680 | 347 | | } |
| | | 348 | | |
| | | 349 | | private static async Task<object?> ScalarAsync( SqlCommand command, bool async, CancellationToken cancellationToken |
| | 845 | 350 | | => async ? await command.ExecuteScalarAsync( cancellationToken ).ConfigureAwait( false ) : command.ExecuteScalar |
| | | 351 | | |
| | | 352 | | /// A typed parameter; dates as <c>datetime2</c> so no precision is lost before the column's own conversion. |
| | | 353 | | private static SqlParameter Parameter( string name, object? value ) |
| | | 354 | | { |
| | 12252 | 355 | | var parameter = new SqlParameter( name, value ?? DBNull.Value ); |
| | | 356 | | |
| | 14406 | 357 | | if ( value is DateTime ) { parameter.SqlDbType = SqlDbType.DateTime2; } |
| | | 358 | | |
| | 12252 | 359 | | return parameter; |
| | | 360 | | } |
| | | 361 | | |
| | 2618 | 362 | | private static SqlParameter Output( string name ) => new( name, SqlDbType.Int ) { Direction = ParameterDirection.Out |
| | | 363 | | |
| | | 364 | | private static IEnumerable<SqlParameter> Values( string prefix, IReadOnlyList<SeedColumnValue> values ) |
| | 2519 | 365 | | => values.Select( ( v, i ) => Parameter( prefix + i.ToString( CultureInfo.InvariantCulture ), v.Value ) ); |
| | | 366 | | |
| | 654 | 367 | | private static string? Truncate( string? value ) => value is { Length: > 256 } ? value[ ..256 ] : value; |
| | | 368 | | } |