private void AppendInsertOperation(IList<BaseOperation> operations, Difference diff)
        {
            var insertOperation = new InsertOperation
            {
                OwnerMetadata = diff.OwnerMetadata,
                OwnerPropertyMetadata = diff.OwnerPropertyMetadata,
                OwnerPrimaryKeyColumn = diff.OwnerMetadata == null ? null : diff.OwnerMetadata.PrimaryKey.Prop.Name,
                Owner = diff.Owner,
                TableName = diff.OwnerMetadata == null ? null : diff.OwnerMetadata.TableName,
                ValueMetadata = diff.ValueMetadata,
                Value = diff.NewValue
            };

            if (IsViableParentUpdateOnManyToOneRelationship(insertOperation, diff))
            {
                AddUpdateOnParentTableForInsertDeleteOfManyToOneChildRow(operations, diff, insertOperation);
            }
            else if (IsViableParentUpdateOnOneToOneWithFkInParent(insertOperation, diff))
            {
                AddUpdateOnParentTableForInsertDeleteOfOneToOneChildRow(operations, diff, insertOperation);
            }
            else if (!ShouldFilterOutForParticularCardinalitiesBecauseFkOnParent(insertOperation))
            {
                AddInsertToListAtCorrectLocation(operations, insertOperation);
            }
        }
 private void AppendUpdateOperation(IList<BaseOperation> operations, Difference diff)
 {
     operations.Add(new UpdateOperation
     {
         ColumnPropertyMetadata = diff.OwnerPropertyMetadata,
         ValueMetadata = diff.ValueMetadata,
         Value = diff.NewValue,
         OwnerPrimaryKeyColumn = diff.OwnerMetadata.PrimaryKey.Prop.Name,
         Owner = diff.Owner,
         OwnerMetadata = diff.OwnerMetadata,
         OwnerPropertyMetadata = diff.OwnerPropertyMetadata,
         TableName = diff.OwnerMetadata.TableName
     });
 }
 private bool IsViableParentUpdateOnOneToOneWithFkInParent(
     BaseInsertDeleteOperation insertDeleteOperation,
     Difference diff)
 {
     return insertDeleteOperation.OwnerPropertyMetadata != null
            && diff.OldOwner != null
            && diff.NewOwner != null
            && (insertDeleteOperation.OwnerPropertyMetadata.IsOneToOneRelationship
                 && insertDeleteOperation.OwnerPropertyMetadata.HasAttribute<ForeignKeyReferenceAttribute>());
 }
 private bool IsViableParentUpdateOnManyToOneRelationship(
     BaseInsertDeleteOperation insertDeleteOperation,
     Difference diff)
 {
     return insertDeleteOperation.OwnerMetadata != null
            && insertDeleteOperation.OwnerPropertyMetadata.IsManyToOneRelationship
            && diff.OldOwner != null
            && diff.NewOwner != null;
 }
        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);
 }