private void PreserveFunctionScalarPropertyMapping(
            CommandProcessorContext cpc, FunctionScalarProperty fsp, Property createdComplexTypeProperty)
        {
            // this represents a path to a scalar Property in the original EntityType properties tree
            var propertiesChain = fsp.GetMappedPropertiesList();

            // we need to create a corresponding path in changed EntityType
            // in order to do that we need to replace first (root) item with a created property from ComplexType...
            propertiesChain.RemoveAt(0);
            propertiesChain.Insert(0, createdComplexTypeProperty);
            // and add the created EntityType complex property as a root of that path
            propertiesChain.Insert(0, _createdComplexProperty);
            var mf = fsp.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction;

            Debug.Assert(
                null != mf,
                "PreserveFunctionScalarPropertyMapping(): Could not find ancestor of type + " + typeof(ModificationFunction).FullName);
            if (null != mf)
            {
                var cmd = new CreateFunctionScalarPropertyTreeCommand(
                    mf, propertiesChain, null, fsp.ParameterName.Target, fsp.Version.Value);
                CommandProcessor.InvokeSingleCommand(cpc, cmd);
            }
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            Debug.Assert(cpc != null, "InvokeInternal is called when ExitingFunctionScalarProperty is null.");

            // safety check, this should never be hit
            if (_existingFunctionScalarProperty == null)
            {
                throw new InvalidOperationException("InvokeInternal is called when ExitingFunctionScalarProperty is null.");
            }

            if (_propChain == null &&
                _pointingNavProp == null &&
                _param == null &&
                _version != null)
            {
                // setting new version only
                if (string.Compare(_existingFunctionScalarProperty.Version.Value, _version, StringComparison.CurrentCulture) != 0)
                {
                    var mfAncestor = _existingFunctionScalarProperty.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction;
                    Debug.Assert(
                        mfAncestor != null,
                        "Bad attempt to set version on FunctionScalarProperty which does not have a ModificationFunction ancestor");
                    if (mfAncestor != null)
                    {
                        Debug.Assert(
                            mfAncestor.FunctionType == ModificationFunctionType.Update,
                            "Bad attempt to set version on FunctionScalarProperty which has a ModificationFunction ancestor whose FunctionType is "
                            +
                            mfAncestor.FunctionType.ToString() + ". Should be " + ModificationFunctionType.Update.ToString());

                        if (mfAncestor.FunctionType == ModificationFunctionType.Update)
                        {
                            _existingFunctionScalarProperty.Version.Value = _version;
                        }
                    }
                }

                _updatedFunctionScalarProperty = _existingFunctionScalarProperty;
                return;
            }

            // if not just setting version then need to delete and re-create FunctionScalarProperty
            // to allow for changes in properties chain
            // where nulls have been passed in, use existing values (except for _pointingNavProp where null
            // indicates "use no NavProp for the new property")
            var mf = _existingFunctionScalarProperty.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction;

            Debug.Assert(mf != null, "Bad attempt to change FunctionScalarProperty which does not have a ModificationFunction ancestor");
            if (mf == null)
            {
                return;
            }

            var propChain = (_propChain != null ? _propChain : _existingFunctionScalarProperty.GetMappedPropertiesList());
            var parameter = (_param != null ? _param : _existingFunctionScalarProperty.ParameterName.Target);
            var version   = (_version != null ? _version : _existingFunctionScalarProperty.Version.Value);

            // now construct delete command for existing FunctionScalarProperty followed by create with new properties
            var cmd1 = _existingFunctionScalarProperty.GetDeleteCommand();
            var cmd2 =
                new CreateFunctionScalarPropertyTreeCommand(mf, propChain, _pointingNavProp, parameter, version);

            cmd2.PostInvokeEvent += (o, eventsArgs) =>
            {
                _updatedFunctionScalarProperty = cmd2.FunctionScalarProperty;
                Debug.Assert(
                    _updatedFunctionScalarProperty != null,
                    "CreateFunctionScalarPropertyTreeCommand should not result in null FunctionScalarProperty");
            };

            var cp = new CommandProcessor(cpc, cmd1, cmd2);

            try
            {
                cp.Invoke();
            }
            finally
            {
                _updatedFunctionScalarProperty = null;
            }
        }
 private void PreserveFunctionScalarPropertyMapping(
     CommandProcessorContext cpc, FunctionScalarProperty fsp, Property createdComplexTypeProperty)
 {
     // this represents a path to a scalar Property in the original EntityType properties tree
     var propertiesChain = fsp.GetMappedPropertiesList();
     // we need to create a corresponding path in changed EntityType
     // in order to do that we need to replace first (root) item with a created property from ComplexType...
     propertiesChain.RemoveAt(0);
     propertiesChain.Insert(0, createdComplexTypeProperty);
     // and add the created EntityType complex property as a root of that path
     propertiesChain.Insert(0, _createdComplexProperty);
     var mf = fsp.GetParentOfType(typeof(ModificationFunction)) as ModificationFunction;
     Debug.Assert(
         null != mf,
         "PreserveFunctionScalarPropertyMapping(): Could not find ancestor of type + " + typeof(ModificationFunction).FullName);
     if (null != mf)
     {
         var cmd = new CreateFunctionScalarPropertyTreeCommand(
             mf, propertiesChain, null, fsp.ParameterName.Target, fsp.Version.Value);
         CommandProcessor.InvokeSingleCommand(cpc, cmd);
     }
 }