Represents an update operation to carry out on a single column in a table. Multiple such operations may be coalesced together into a single UpdateCommand, which results in the generation of a single UPDATE SQL statement that updates multiple columns.
Inheritance: BaseOperation
        private void ValidateUpdateOperation(UpdateOperation update)
        {
            var tableMetadata = update.OwnerMetadata;

            if (null != tableMetadata)
            {
                if (tableMetadata.IsReferenceData)
                {
                    var columnMetadata = update.OwnerPropertyMetadata;
                    if (!tableMetadata.HasUpdateableForeignKeys)
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "You cannot perform UPDATEs on a reference data table with no updateable foreign keys. "
                                                                + "Attempt was made to UPDATE table {0}, column {1}.",
                                                                tableMetadata.TableName,
                                                                columnMetadata == null ? "(unknown column)" : columnMetadata.ColumnName));
                    }

                    if (null != columnMetadata && !columnMetadata.HasAttribute <ForeignKeyReferenceAttribute>())
                    {
                        throw new InvalidOperationException(string.Format(
                                                                "You cannot UPDATE non-foreign key columns on a reference data table with updateable foreign keys. "
                                                                + "Attempt was made to UPDATE table {0}, column {1}.",
                                                                tableMetadata.TableName,
                                                                columnMetadata.ColumnName));
                    }
                }
            }
        }
        public void AddOperation(UpdateOperation operation)
        {
            var name = TableName;

            if (null != name && operation.TableName != name)
            {
                throw new ArgumentException(string.Format(
                                                "Table name mismatch for UPDATE command. Expected: {0}. Actual: {1}.",
                                                name,
                                                operation.TableName),
                                            "operation");
            }

            var pk = PrimaryKeyAsObject;

            if (null != pk &&
                !PrimaryKeyComparer.SuppliedPrimaryKeyValuesMatch(
                    operation.OwnerMetadata,
                    pk,
                    operation.OwnerPrimaryKeyAsObject))//operation.OwnerPrimaryKey != pk.Value)
            {
                throw new ArgumentException(string.Format(
                                                "Primary key mismatch for UPDATE command on table {0}. Expected: {1}. Actual: {2}.",
                                                name,
                                                pk,
                                                operation.OwnerPrimaryKeyAsObject),
                                            "operation");
            }

            name = PrimaryKeyColumn;
            if (null != name && operation.OwnerPrimaryKeyColumn != name)
            {
                throw new ArgumentException(string.Format(
                                                "Primary key column mismatch for UPDATE command on table {0}. Expected: {1}. Actual: {2}.",
                                                TableName,
                                                name,
                                                operation.OwnerPrimaryKeyColumn),
                                            "operation");
            }

            TableName        = operation.TableName;
            PrimaryKeyColumn = operation.OwnerPrimaryKeyColumn;

            _operations.Add(operation);
        }
Beispiel #3
0
        private static void AddUpdateOnParentTableForInsertDeleteOfManyToOneChildRow(
            IList <BaseOperation> operations,
            Difference diff,
            BaseInsertDeleteOperation insertOperation)
        {
            var updateOperation = new UpdateOperation
            {
                OwnerMetadata         = insertOperation.OwnerMetadata,
                OwnerPropertyMetadata = insertOperation.OwnerPropertyMetadata,
                OwnerPrimaryKeyColumn = insertOperation.OwnerPrimaryKeyColumn,
                Owner     = insertOperation.Owner,
                TableName = insertOperation.TableName,
                ColumnPropertyMetadata = diff.OwnerPropertyMetadata,
                ValueMetadata          = diff.ValueMetadata,
                Value = diff.NewValue
            };

            operations.Add(updateOperation);
        }
        public void AddOperation(UpdateOperation operation)
        {
            var name = TableName;
            if (null != name && operation.TableName != name)
            {
                throw new ArgumentException(string.Format(
                    "Table name mismatch for UPDATE command. Expected: {0}. Actual: {1}.",
                    name,
                    operation.TableName),
                    "operation");
            }

            var pk = PrimaryKeyAsObject;
            if (null != pk
                && !PrimaryKeyComparer.SuppliedPrimaryKeyValuesMatch(
                    operation.OwnerMetadata,
                    pk,
                    operation.OwnerPrimaryKeyAsObject))//operation.OwnerPrimaryKey != pk.Value)
            {
                throw new ArgumentException(string.Format(
                    "Primary key mismatch for UPDATE command on table {0}. Expected: {1}. Actual: {2}.",
                    name,
                    pk,
                    operation.OwnerPrimaryKeyAsObject),
                    "operation");
            }

            name = PrimaryKeyColumn;
            if (null != name && operation.OwnerPrimaryKeyColumn != name)
            {
                throw new ArgumentException(string.Format(
                    "Primary key column mismatch for UPDATE command on table {0}. Expected: {1}. Actual: {2}.",
                    TableName,
                    name,
                    operation.OwnerPrimaryKeyColumn),
                    "operation");
            }

            TableName = operation.TableName;
            PrimaryKeyColumn = operation.OwnerPrimaryKeyColumn;

            _operations.Add(operation);
        }
        public static bool IsReverseUpdateWithChildReferencingParent(UpdateOperation update)
        {
            var ownerPropMeta = update.OwnerPropertyMetadata;
            if (null == ownerPropMeta)
            {
                return false;
            }

            if (!ownerPropMeta.HasAttribute<OneToManyAttribute>()
                && !ownerPropMeta.HasAttribute<OneToOneAttribute>())
            {
                return false;
            }

            var valueMeta = update.ValueMetadata;
            if (valueMeta.IsReferenceData
                && valueMeta.HasUpdateableForeignKeys)
            {
                return true;
            }

            return ownerPropMeta.HasAttribute<ReferenceDataAttribute>()
                && ownerPropMeta.GetAttribute<ReferenceDataAttribute>().HasUpdateableForeignKeys;
        }
        private static void AddUpdateOnParentTableForInsertDeleteOfOneToOneChildRow(IList<BaseOperation> operations, Difference diff,
            BaseInsertDeleteOperation insertDeleteOperation)
        {
            var updateOperation = new UpdateOperation
            {
                OwnerMetadata = insertDeleteOperation.OwnerMetadata,
                OwnerPropertyMetadata = insertDeleteOperation.OwnerPropertyMetadata,
                OwnerPrimaryKeyColumn = insertDeleteOperation.OwnerPrimaryKeyColumn,
                Owner = insertDeleteOperation.Owner,
                TableName = insertDeleteOperation.OwnerMetadata.TableName,
                ColumnPropertyMetadata = diff.OwnerPropertyMetadata,
                ValueMetadata = diff.ValueMetadata,
                Value = diff.NewValue
            };

            if (insertDeleteOperation is DeleteOperation)
            {
                operations.Add(updateOperation);
            }

            if (!insertDeleteOperation.ValueMetadata.IsReferenceData && !insertDeleteOperation.OwnerPropertyMetadata.HasAttribute<ReferenceDataAttribute>())
            {
                operations.Add(insertDeleteOperation);
            }

            //  If it's an INSERT add the update here
            if (insertDeleteOperation is InsertOperation)
            {
                operations.Add(updateOperation);
            }
        }
 private static void AddUpdateOnParentTableForInsertDeleteOfManyToOneChildRow(
     IList<BaseOperation> operations,
     Difference diff,
     BaseInsertDeleteOperation insertOperation)
 {
     var updateOperation = new UpdateOperation
     {
         OwnerMetadata = insertOperation.OwnerMetadata,
         OwnerPropertyMetadata = insertOperation.OwnerPropertyMetadata,
         OwnerPrimaryKeyColumn = insertOperation.OwnerPrimaryKeyColumn,
         Owner = insertOperation.Owner,
         TableName = insertOperation.TableName,
         ColumnPropertyMetadata = diff.OwnerPropertyMetadata,
         ValueMetadata = diff.ValueMetadata,
         Value = diff.NewValue
     };
     operations.Add(updateOperation);
 }
 private string GetNewUpdateTableName(UpdateOperation update)
 {
     return(ReverseUpdateHelper.IsReverseUpdateWithChildReferencingParent(update)
         ? update.ValueMetadata.TableName
         : update.TableName);
 }
 private DtoMetadata GetNewUpdateMetadata(UpdateOperation update)
 {
     return(ReverseUpdateHelper.IsReverseUpdateWithChildReferencingParent(update)
         ? update.ValueMetadata
         : update.OwnerMetadata);
 }
 private object GetNewUpdatePrimaryKeyValue(UpdateOperation update)
 {
     return(ReverseUpdateHelper.IsReverseUpdateWithChildReferencingParent(update)
         ? update.ValueMetadata.GetPrimaryKeyValueAsObject(update.Value)
         : update.OwnerPrimaryKeyAsObject);
 }
 private object GetNewUpdatePrimaryKeyValue(UpdateOperation update)
 {
     return ReverseUpdateHelper.IsReverseUpdateWithChildReferencingParent(update)
         ? update.ValueMetadata.GetPrimaryKeyValueAsObject(update.Value)
         : update.OwnerPrimaryKeyAsObject;
 }
 private string GetNewUpdateTableName(UpdateOperation update)
 {
     return ReverseUpdateHelper.IsReverseUpdateWithChildReferencingParent(update)
         ? update.ValueMetadata.TableName
         : update.TableName;
 }
 private DtoMetadata GetNewUpdateMetadata(UpdateOperation update)
 {
     return ReverseUpdateHelper.IsReverseUpdateWithChildReferencingParent(update)
         ? update.ValueMetadata
         : update.OwnerMetadata;
 }
        private void ValidateUpdateOperation(UpdateOperation update)
        {
            var tableMetadata = update.OwnerMetadata;
            if (null != tableMetadata)
            {
                if (tableMetadata.IsReferenceData)
                {
                    var columnMetadata = update.OwnerPropertyMetadata;
                    if (!tableMetadata.HasUpdateableForeignKeys)
                    {
                        throw new InvalidOperationException(string.Format(
                            "You cannot perform UPDATEs on a reference data table with no updateable foreign keys. "
                            + "Attempt was made to UPDATE table {0}, column {1}.",
                            tableMetadata.TableName,
                            columnMetadata == null ? "(unknown column)" : columnMetadata.ColumnName));
                    }

                    if (null != columnMetadata && !columnMetadata.HasAttribute<ForeignKeyReferenceAttribute>())
                    {
                        throw new InvalidOperationException(string.Format(
                            "You cannot UPDATE non-foreign key columns on a reference data table with updateable foreign keys. "
                            + "Attempt was made to UPDATE table {0}, column {1}.",
                            tableMetadata.TableName,
                            columnMetadata.ColumnName));
                    }
                }
            }
        }