Exemplo n.º 1
0
        /// <summary>
        /// Builds key mappings between source model and target <see cref="KeyOutput"/> model.
        /// </summary>
        /// <param name="mapper">The column mapper.</param>
        /// <param name="source">The source model.</param>
        /// <param name="target">The target <see cref="KeyOutput"/> model.</param>
        public static void BuildKeyMappings(ColumnMapper mapper, Model source, KeyOutput target)
        {
            var sourceKey = source.PrimaryKey;

            if (sourceKey == null)
            {
                throw new InvalidOperationException(DiagnosticMessages.DbTable_NoPrimaryKey(source));
            }

            var targetKey = target.PrimaryKey;

            if (targetKey == null)
            {
                throw new InvalidOperationException(DiagnosticMessages.DbTable_NoPrimaryKey(target));
            }

            if (targetKey.Count != sourceKey.Count)
            {
                throw new InvalidOperationException(DiagnosticMessages.DbTable_GetKeyMappings_CannotMatch);
            }

            for (int i = 0; i < targetKey.Count; i++)
            {
                var targetColumn = targetKey[i].Column;
                var sourceColumn = sourceKey[i].Column;
                if (targetColumn.DataType != sourceColumn.DataType)
                {
                    throw new InvalidOperationException(DiagnosticMessages.DbTable_GetKeyMappings_CannotMatch);
                }

                mapper.Select(sourceColumn, i);
            }
        }
Exemplo n.º 2
0
        private async Task <DbTable <KeyOutput> > CreateKeyOutputAsync(Model sourceModel, CancellationToken cancellationToken)
        {
            var keyOutput = new KeyOutput(sourceModel);
            var result    = CreateTempTableInstance(keyOutput);

            await CreateTableAsync(keyOutput, true, cancellationToken);

            return(result);
        }
Exemplo n.º 3
0
            private static ColumnSort[] GetColumns(KeyOutput _, CandidateKey primaryKey)
            {
                var result = new ColumnSort[primaryKey.Count];

                for (int i = 0; i < primaryKey.Count; i++)
                {
                    var columnSort = primaryKey[i];
                    result[i] = new ColumnSort(columnSort.Column.Clone(_), columnSort.Direction);
                }
                return(result);
            }
Exemplo n.º 4
0
 public PK(KeyOutput keyOutput, CandidateKey primaryKey)
     : base(GetColumns(keyOutput, primaryKey))
 {
 }