| | | 1 | | namespace ZhEaIsNsAaBn.DbSeeder; |
| | | 2 | | |
| | | 3 | | /// One table file bound to the EF model: columns resolved, values converted to provider values, managed fields found. |
| | | 4 | | internal sealed class SeedBoundTable |
| | | 5 | | { |
| | | 6 | | public required string File { get; init; } |
| | | 7 | | |
| | | 8 | | public required SeedTable Table { get; init; } |
| | | 9 | | |
| | | 10 | | public required SeedEntityRoles Roles { get; init; } |
| | | 11 | | |
| | | 12 | | /// Managed fields the entity really maps (role → column). |
| | | 13 | | public required IReadOnlyDictionary<SeedRole, SeedColumn> Managed { get; init; } |
| | | 14 | | |
| | | 15 | | public required IReadOnlyList<SeedColumn> UpsertColumns { get; init; } |
| | | 16 | | |
| | | 17 | | public required IReadOnlyList<IReadOnlyList<object?>> UpsertRows { get; init; } |
| | | 18 | | |
| | | 19 | | public required IReadOnlyList<IReadOnlyList<object?>> DeleteKeys { get; init; } |
| | | 20 | | |
| | | 21 | | public required IReadOnlyList<IReadOnlyList<object?>> SoftDeleteKeys { get; init; } |
| | | 22 | | |
| | | 23 | | public required IReadOnlyList<IReadOnlyList<object?>> RestoreKeys { get; init; } |
| | | 24 | | |
| | | 25 | | /// The <c>Before</c> rows (data columns only), for rollback. |
| | | 26 | | public required IReadOnlyList<SeedColumn> BeforeColumns { get; init; } |
| | | 27 | | |
| | | 28 | | public required IReadOnlyList<IReadOnlyList<object?>> BeforeRows { get; init; } |
| | | 29 | | |
| | | 30 | | /// Foreign keys to the same table whose columns are all written (rows are levelled). |
| | | 31 | | public required IReadOnlyList<IForeignKey> SelfReferences { get; init; } |
| | | 32 | | |
| | | 33 | | /// Whether the rows are matched on a business key (<c>MatchBy</c>) rather than the primary key. |
| | | 34 | | public required bool MatchesByBusinessKey { get; init; } |
| | | 35 | | |
| | | 36 | | |
| | 8858 | 37 | | public IEntityType EntityType => Table.EntityType; |
| | | 38 | | |
| | 8132 | 39 | | public SeedColumn? this[ SeedRole role ] => Managed.GetValueOrDefault( role ); |
| | | 40 | | |
| | | 41 | | |
| | | 42 | | /// The match-key text of each row of <paramref name="rows"/> (written with <paramref name="columns"/>). |
| | | 43 | | public IEnumerable<string> KeysOf( IReadOnlyList<SeedColumn> columns, IEnumerable<IReadOnlyList<object?>> rows ) |
| | | 44 | | { |
| | 697 | 45 | | var indexes = Table.MatchColumns.Select( m => columns.Select( c => c.ColumnName ).ToList().IndexOf( m.ColumnName |
| | | 46 | | |
| | 697 | 47 | | return rows.Select( r => SeedRowLevels.Key( r, indexes ) ); |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | /// The match-key text of key rows (values in <see cref="SeedTable.MatchColumns"/> order). |
| | 217 | 51 | | public IEnumerable<string> KeysOf( IEnumerable<IReadOnlyList<object?>> keyRows ) => keyRows.Select( r => SeedRowLeve |
| | | 52 | | } |