Exemplo n.º 1
0
        /// <summary>
        ///     Generates the commands that correspond to this operation.
        /// </summary>
        /// <returns> The commands that correspond to this operation. </returns>
        public virtual IEnumerable <ModificationCommand> GenerateModificationCommands([CanBeNull] IModel model)
        {
            Debug.Assert(KeyColumns.Length == KeyValues.GetLength(1),
                         $"The number of key values doesn't match the number of keys (${KeyColumns.Length})");
            Debug.Assert(Columns.Length == Values.GetLength(1),
                         $"The number of values doesn't match the number of keys (${Columns.Length})");
            Debug.Assert(KeyValues.GetLength(0) == Values.GetLength(0),
                         $"The number of key values doesn't match the number of values (${KeyValues.GetLength(0)})");

            var properties = model != null
                ? TableMapping.GetTableMapping(model, Table, Schema)?.GetPropertyMap()
                : null;

            for (var i = 0; i < KeyValues.GetLength(0); i++)
            {
                var keys = new ColumnModification[KeyColumns.Length];
                for (var j = 0; j < KeyColumns.Length; j++)
                {
                    keys[j] = new ColumnModification(
                        KeyColumns[j], originalValue: null, value: KeyValues[i, j], property: properties?.Find(KeyColumns[j]),
                        isRead: false, isWrite: false, isKey: true, isCondition: true);
                }

                var modifications = new ColumnModification[Columns.Length];
                for (var j = 0; j < Columns.Length; j++)
                {
                    modifications[j] = new ColumnModification(
                        Columns[j], originalValue: null, value: Values[i, j], property: properties?.Find(Columns[j]),
                        isRead: false, isWrite: true, isKey: true, isCondition: false);
                }

                yield return(new ModificationCommand(Table, Schema, keys.Concat(modifications).ToArray()));
            }
        }
        /// <summary>
        ///     Generates the commands that correspond to this operation.
        /// </summary>
        /// <returns> The commands that correspond to this operation. </returns>
        public virtual IEnumerable <ModificationCommand> GenerateModificationCommands()
        {
            Debug.Assert(KeyColumns.Length == KeyValues.GetLength(1),
                         $"The number of key values doesn't match the number of keys (${KeyColumns.Length})");
            Debug.Assert(Columns.Length == Values.GetLength(1),
                         $"The number of values doesn't match the number of keys (${Columns.Length})");
            Debug.Assert(KeyValues.GetLength(0) == Values.GetLength(0),
                         $"The number of key values doesn't match the number of values (${KeyValues.GetLength(0)})");

            for (var i = 0; i < KeyValues.GetLength(0); i++)
            {
                var keys = new ColumnModification[KeyColumns.Length];
                for (var j = 0; j < KeyColumns.Length; j++)
                {
                    keys[j] = new ColumnModification(
                        KeyColumns[j], originalValue: null, value: KeyValues[i, j],
                        isRead: false, isWrite: false, isKey: true, isCondition: true);
                }

                var modifications = new ColumnModification[Columns.Length];
                for (var j = 0; j < Columns.Length; j++)
                {
                    modifications[j] = new ColumnModification(
                        Columns[j], originalValue: null, value: Values[i, j],
                        isRead: false, isWrite: true, isKey: true, isCondition: false);
                }

                yield return(new ModificationCommand(Table, Schema, keys.Concat(modifications).ToArray()));
            }
        }
        public virtual IEnumerable <ModificationCommand> GenerateModificationCommands([CanBeNull] IModel model)
        {
            Check.DebugAssert(
                KeyColumns.Length == KeyValues.GetLength(1),
                $"The number of key values doesn't match the number of keys (${KeyColumns.Length})");
            Check.DebugAssert(
                Columns.Length == Values.GetLength(1),
                $"The number of values doesn't match the number of keys (${Columns.Length})");
            Check.DebugAssert(
                KeyValues.GetLength(0) == Values.GetLength(0),
                $"The number of key values doesn't match the number of values (${KeyValues.GetLength(0)})");

            var table         = model?.GetRelationalModel().FindTable(Table, Schema);
            var keyProperties = table != null
                ? MigrationsModelDiffer.GetMappedProperties(table, KeyColumns)
                : null;

            var properties = table != null
                ? MigrationsModelDiffer.GetMappedProperties(table, Columns)
                : null;

            for (var i = 0; i < KeyValues.GetLength(0); i++)
            {
                var keys = new ColumnModification[KeyColumns.Length];
                for (var j = 0; j < KeyColumns.Length; j++)
                {
                    keys[j] = new ColumnModification(
                        KeyColumns[j], originalValue: null, value: KeyValues[i, j], property: keyProperties?[j],
                        columnType: KeyColumnTypes?[j], isRead: false, isWrite: false, isKey: true, isCondition: true,
                        sensitiveLoggingEnabled: false);
                }

                var modifications = new ColumnModification[Columns.Length];
                for (var j = 0; j < Columns.Length; j++)
                {
                    modifications[j] = new ColumnModification(
                        Columns[j], originalValue: null, value: Values[i, j], property: properties?[j],
                        columnType: ColumnTypes?[j], isRead: false, isWrite: true, isKey: true, isCondition: false,
                        sensitiveLoggingEnabled: false);
                }

                yield return(new ModificationCommand(Table, Schema, keys.Concat(modifications).ToArray(), sensitiveLoggingEnabled: false));
            }
        }