示例#1
0
        // <summary>
        //     The parent item for the function mapping view model always has 3 children; insert, update and delete.  If there isn’t
        //     a function mapped for any of these, then there is still a view model item since we want to display the ‘creator node’ text.
        //     Thus, we don't call this.Parent.RemoveChild(this).
        // </summary>
        internal override void DeleteModelItem(CommandProcessorContext cpc)
        {
            Debug.Assert(ModelItem != null, "We are trying to delete a null ModelItem");
            if (IsModelItemDeleted() == false)
            {
                // create a context if we weren't passed one
                if (cpc == null)
                {
                    cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_DeleteFunctionMapping);
                }

                // use the item's delete command
                var deleteCommand = ModificationFunction.GetDeleteCommand(MappingFunctionEntityType.EntityType, Function, _functionType);
                deleteCommand.PostInvokeEvent += (o, eventsArgs) =>
                {
                    ModelItem = null;
                    ClearChildren();
                };

                DeleteEFElementCommand.DeleteInTransaction(cpc, deleteCommand);
            }

            // if IsModelItemDeleted == true, just make sure that it is null anyways
            ModelItem = null;
        }
        /// <summary>
        ///     Creates a FunctionScalarProperty element (potentially within multiple ComplexProperty elements) that
        ///     maps the Property at the bottom of the passed in property chain to the passed in Parameter
        ///     within the passed in ModificationFunction.
        /// </summary>
        /// <param name="modificationFunction">ultimate parent for ScalarProperty created by this</param>
        /// <param name="propertyChain">property to be inserted, preceded by its ComplexProperty parents if appropriate</param>
        /// <param name="navPropPointingToProperty">
        ///     Optional - if present indicates the Scalar Property at
        ///     the bottom of the propertyChain was reached via a NavProp (propertyChain will have only 1 Property)
        /// </param>
        /// <param name="parameter">The sproc parameter to which we will map</param>
        internal CreateFunctionScalarPropertyTreeCommand(
            ModificationFunction modificationFunction, List <Property> propertyChain,
            NavigationProperty navPropPointingToProperty, Parameter parameter, string version)
        {
            CommandValidation.ValidateModificationFunction(modificationFunction);
            CommandValidation.ValidateParameter(parameter);
            if (null != navPropPointingToProperty)
            {
                CommandValidation.ValidateNavigationProperty(navPropPointingToProperty);
            }
            Debug.Assert(propertyChain.Count > 0, "Properties list should contain at least one element");

            _modificationFunction      = modificationFunction;
            _propertyChain             = propertyChain;
            _navPropPointingToProperty = navPropPointingToProperty;
            if (_navPropPointingToProperty != null)
            {
                Debug.Assert(
                    propertyChain.Count == 1,
                    "When creating a FunctionScalarProperty via a NavigationProperty propertyChain should have only 1 element, but it has "
                    + propertyChain.Count);
            }
            _parameter = parameter;
            Debug.Assert(
                string.IsNullOrEmpty(version) ||
                ModelConstants.FunctionScalarPropertyVersionOriginal.Equals(version, StringComparison.Ordinal) ||
                ModelConstants.FunctionScalarPropertyVersionCurrent.Equals(version, StringComparison.Ordinal),
                "version should be empty or " + ModelConstants.FunctionScalarPropertyVersionOriginal + " or "
                + ModelConstants.FunctionScalarPropertyVersionCurrent + ". Actual value: " + version);
            _version = version;
        }
示例#3
0
        /// <summary>
        ///     Creates a FunctionComplexProperty within a ModificationFunction mapped to the passed in
        ///     C-side property.
        /// </summary>
        /// <param name="parentModificationFunction">The parent inside which this FunctionComplexProperty will be placed</param>
        /// <param name="property">This must be a valid Property from the C-Model.</param>
        internal CreateFunctionComplexPropertyCommand(ModificationFunction parentModificationFunction, ComplexConceptualProperty property)
            : base(PrereqId)
        {
            CommandValidation.ValidateModificationFunction(parentModificationFunction);
            CommandValidation.ValidateConceptualProperty(property);

            _parentModificationFunction = parentModificationFunction;
            _property = property;
        }
        internal SetRowsAffectedParameterCommand(ModificationFunction modificationFunction, Parameter param)
        {
            Debug.Assert(
                modificationFunction != null,
                typeof(SetRowsAffectedParameterCommand).Name + ": constructor cannot operate on null ModificationFunction");

            _modificationFunction = modificationFunction;
            _param = param;
        }
示例#5
0
 public MappingModificationFunctionMapping(EditingContext context, ModificationFunction functionMapping, MappingEFElement parent)
     : base(context, functionMapping, parent)
 {
     if (functionMapping != null)
     {
         _functionType   = functionMapping.FunctionType;
         _properties     = new MappingFunctionScalarProperties(context, functionMapping, this);
         _resultBindings = new MappingResultBindings(context, functionMapping, this);
     }
 }
示例#6
0
        private static FunctionComplexProperty CreateComplexPropertyUsingModificationFunction(
            ModificationFunction parentModificationFunction, ComplexConceptualProperty property)
        {
            // make sure that we don't already have one
            var fcp = parentModificationFunction.FindFunctionComplexProperty(property);

            if (fcp == null)
            {
                fcp = CreateNewFunctionComplexProperty(parentModificationFunction, property);
                parentModificationFunction.AddComplexProperty(fcp);
            }

            return(fcp);
        }
        /// <summary>
        ///     Creates a ScalarProperty element that maps the passed in Property to the Parameter, inside
        ///     the parent ModificationFunction.
        /// </summary>
        /// <param name="property"></param>
        /// <param name="navPropPointingToProperty"></param>
        /// <param name="parm"></param>
        /// <param name="version">Optional</param>
        internal CreateFunctionScalarPropertyCommand(
            ModificationFunction parentModificationFunction,
            Property property, NavigationProperty navPropPointingToProperty, Parameter parm, string version)
        {
            CommandValidation.ValidateProperty(property);
            CommandValidation.ValidateParameter(parm);
            CommandValidation.ValidateModificationFunction(parentModificationFunction);

            // we don't require a non-null navigation property since the function scalar property could exist
            // directly in its parent
            if (navPropPointingToProperty != null)
            {
                CommandValidation.ValidateNavigationProperty(navPropPointingToProperty);
            }

            _property            = property;
            _pointingNavProperty = navPropPointingToProperty;
            _parm          = parm;
            _version       = version;
            _parentModFunc = parentModificationFunction;
        }
        /// <summary>
        ///     Creates a ScalarProperty element that maps the passed in Property to the Parameter, inside
        ///     the ComplexProperty given by the passed in CreateFunctionComplexPropertyCommand pre-req Command.
        /// </summary>
        /// <param name="prereq"></param>
        /// <param name="property"></param>
        /// <param name="navPropPointingToProperty"></param>
        /// <param name="parm"></param>
        /// <param name="version">Optional</param>
        internal CreateFunctionScalarPropertyCommand(
            CreateFunctionComplexPropertyCommand prereq, Property property,
            NavigationProperty navPropPointingToProperty, Parameter parm, string version)
            : base(PrereqId)
        {
            ValidatePrereqCommand(prereq);
            CommandValidation.ValidateProperty(property);
            CommandValidation.ValidateParameter(parm);

            // we don't require a non-null navigation property since the function scalar property could exist
            // directly in its parent
            if (navPropPointingToProperty != null)
            {
                CommandValidation.ValidateNavigationProperty(navPropPointingToProperty);
            }

            _property            = property;
            _pointingNavProperty = navPropPointingToProperty;
            _parm          = parm;
            _version       = version;
            _parentModFunc = null; // parent should be a ComplexProperty from the prereq Command

            AddPreReqCommand(prereq);
        }
        private static Symbol GetSymbolBasedOnModificationFunction(
            EFArtifactSet artifactSet, ModificationFunction mod, string refName)
        {
            Debug.Assert(mod != null, "GetSymbolBasedOnModificationFunction passed a null ModificationFunction");

            Symbol symbol = null;

            if (mod.FunctionName.Status == BindingStatus.Known)
            {
                symbol = new Symbol(mod.FunctionName.Target.NormalizedName, refName);

                Debug.Assert(artifactSet != null, "GetSymbolBasedOnModificationFunction passed a null EFArtifactSet");
                if (null != artifactSet)
                {
                    var item = artifactSet.LookupSymbol(symbol);
                    if (item == null)
                    {
                        symbol = null;
                    }
                }
            }

            return(symbol);
        }
        protected override void InvokeInternal(CommandProcessorContext cpc)
        {
            // safety check, this should never be hit
            Debug.Assert(
                _conceptualEntityType != null && _function != null,
                "InvokeInternal is called when _conceptualEntityType or _function is null");
            if (_conceptualEntityType == null ||
                _function == null)
            {
                throw new InvalidOperationException("InvokeInternal is called when _conceptualEntityType or _function is null");
            }

            // see if we have the ETM we need, if not create it
            var entityTypeMapping = ModelHelper.FindEntityTypeMapping(
                cpc,
                _conceptualEntityType,
                EntityTypeMappingKind.Function,
                true);

            Debug.Assert(entityTypeMapping != null, "Failed to create the EntityTypeMapping to house this item");
            if (entityTypeMapping == null)
            {
                throw new ParentItemCreationFailureException();
            }

            // if we created a new ETM, then we'll need to also create the ModificationFunctionMapping
            if (entityTypeMapping.ModificationFunctionMapping == null)
            {
                entityTypeMapping.ModificationFunctionMapping = new ModificationFunctionMapping(entityTypeMapping, null);
                XmlModelHelper.NormalizeAndResolve(entityTypeMapping.ModificationFunctionMapping);
            }
            Debug.Assert(
                entityTypeMapping.ModificationFunctionMapping != null,
                "Failed to create the ModificationFunctionMapping node to house this item");
            if (entityTypeMapping.ModificationFunctionMapping == null)
            {
                throw new ParentItemCreationFailureException();
            }

            // now go and actually create the item
            if (_type == ModificationFunctionType.Insert)
            {
                _modificationFunction = new InsertFunction(entityTypeMapping.ModificationFunctionMapping, null);
                entityTypeMapping.ModificationFunctionMapping.InsertFunction = _modificationFunction as InsertFunction;
            }
            else if (_type == ModificationFunctionType.Update)
            {
                _modificationFunction = new UpdateFunction(entityTypeMapping.ModificationFunctionMapping, null);
                entityTypeMapping.ModificationFunctionMapping.UpdateFunction = _modificationFunction as UpdateFunction;
            }
            else if (_type == ModificationFunctionType.Delete)
            {
                _modificationFunction = new DeleteFunction(entityTypeMapping.ModificationFunctionMapping, null);
                entityTypeMapping.ModificationFunctionMapping.DeleteFunction = _modificationFunction as DeleteFunction;
            }
            Debug.Assert(_modificationFunction != null, "Failed to create the new function mapping");
            if (_modificationFunction == null)
            {
                throw new ItemCreationFailureException();
            }

            // set the function into the function mapping
            _modificationFunction.FunctionName.SetRefName(_function);

            // set the RowsAffectedParameter
            var cmd = new SetRowsAffectedParameterCommand(_modificationFunction, _rowsAffectedParameter);

            CommandProcessor.InvokeSingleCommand(cpc, cmd);

            XmlModelHelper.NormalizeAndResolve(_modificationFunction);
        }
 /// <summary>
 ///     Delete the passed in function mapping
 /// </summary>
 /// <param name="mf"></param>
 internal DeleteFunctionMappingCommand(ModificationFunction mf)
     : base(mf)
 {
     CommandValidation.ValidateModificationFunction(mf);
 }
示例#12
0
 internal static void ValidateModificationFunction(ModificationFunction mf)
 {
     ValidateEFElement(mf);
 }
示例#13
0
 public MappingResultBindings(EditingContext context, ModificationFunction functionMapping, MappingEFElement parent)
     : base(context, functionMapping, parent)
 {
 }
        private void ProcessModificationFunction(EntityInfo info, ModificationFunction function)
        {
            if (function == null)
            {
                return;
            }

            // make sure that we don't have any extra scalars (i.e. from entities that are no longer parents of this entity)
            // so gather the list of all SPs we expect to be here
            var expectedMappedProperties = new List <Property>();

            expectedMappedProperties.AddRange(info.KeyProperties);
            expectedMappedProperties.AddRange(info.NonKeyProperties);
            if (info.Parent != null)
            {
                GatherNonKeyPropertiesFromAllParents(info.Parent, expectedMappedProperties);
            }

            // remove any that aren't in our expected list
            foreach (var sp in function.ScalarProperties())
            {
                if (expectedMappedProperties.Contains(sp.Name.Target) == false)
                {
                    AddToDeleteList(sp);
                }
            }

            // make sure that we don't have any extra AssociationEnds
            var cet = info.EntityType;

            Debug.Assert(cet != null, "EntityType is not a ConceptualEntityType");
            var selfAndBaseTypes = new List <ConceptualEntityType>(cet.SafeSelfAndBaseTypes);

            foreach (var end in function.AssociationEnds())
            {
                var from = end.From.Target;
                var to   = end.To.Target;
                if (from != null &&
                    to != null &&
                    from.Role.Target != null &&
                    to.Role.Target != null)
                {
                    var fromType = from.Role.Target.Type.Target as ConceptualEntityType;
                    var toType   = to.Role.Target.Type.Target as ConceptualEntityType;

                    Debug.Assert(
                        from.Role.Target.Type.Target != null ? fromType != null : true, "fromType EntityType is not a ConceptualEntityType");
                    Debug.Assert(
                        to.Role.Target.Type.Target != null ? toType != null : true, "toType EntityType is not a ConceptualEntityType");

                    if (fromType != null &&
                        toType != null)
                    {
                        if (selfAndBaseTypes.Contains(fromType) ||
                            selfAndBaseTypes.Contains(toType))
                        {
                            continue;
                        }
                    }
                }

                AddToDeleteList(end);
            }
        }
 public MappingFunctionScalarProperties(EditingContext context, ModificationFunction functionMapping, MappingEFElement parent)
     : base(context, functionMapping, parent)
 {
 }
        internal static FunctionScalarProperty CreateFunctionScalarPropertyInAssociationEnd(
            ModificationFunction mf, Property entityProperty, NavigationProperty pointingNavProperty, Parameter parm, string version)
        {
            // in creating the function scalar property, we modify the AssociationEnd depending on the navigation property that is
            // pointing to the actual property. If we don't have this navigation property we can't do anything.
            Debug.Assert(
                pointingNavProperty != null,
                "We need the navigation property pointing to the property in order to create the mapping function scalar property");
            if (pointingNavProperty == null)
            {
                throw new CannotLocateReferencedItemException();
            }

            Debug.Assert(pointingNavProperty.Relationship.Target != null, "Where is the Association for this navigation property?");
            if (pointingNavProperty.Relationship.Target == null)
            {
                throw new CannotLocateReferencedItemException();
            }

            var assocSet       = pointingNavProperty.Relationship.Target.AssociationSet;
            var navPropFromEnd = pointingNavProperty.FromRole.Target;
            var navPropToEnd   = pointingNavProperty.ToRole.Target;

            Debug.Assert(null != navPropFromEnd, "Null FromRole for pointingNavProperty " + pointingNavProperty.ToPrettyString());
            Debug.Assert(null != navPropToEnd, "Null ToRole for pointingNavProperty " + pointingNavProperty.ToPrettyString());

            AssociationSetEnd assocSetFromEnd = null;
            AssociationSetEnd assocSetToEnd   = null;

            // figure which end is which
            // Note: it is valid for the NavigationProperty to point to
            // an EntityType in the same inheritance hierarchy
            foreach (var end in assocSet.AssociationSetEnds())
            {
                if (end.Role.Target == navPropFromEnd)
                {
                    Debug.Assert(
                        null == assocSetFromEnd,
                        "pointingNavProperty From End " + navPropFromEnd.ToPrettyString()
                        + " matches more than 1 AssociationSetEnd for AssociationSet " + assocSet.ToPrettyString());
                    assocSetFromEnd = end;
                }
                else if (end.Role.Target == navPropToEnd)
                {
                    Debug.Assert(
                        null == assocSetToEnd,
                        "pointingNavProperty To End " + navPropToEnd.ToPrettyString()
                        + " matches more than 1 AssociationSetEnd for AssociationSet " + assocSet.ToPrettyString());
                    assocSetToEnd = end;
                }
            }
            Debug.Assert(null != assocSetFromEnd, "Cannot find From end of AssociationSet " + assocSet.ToPrettyString());
            Debug.Assert(null != assocSetToEnd, "Cannot find To end of AssociationSet " + assocSet.ToPrettyString());

            // see if we already have this AssociationEnd
            FunctionAssociationEnd fae = null;

            foreach (var funcAssocEnd in mf.AssociationEnds())
            {
                if (funcAssocEnd.AssociationSet.Target == assocSet &&
                    funcAssocEnd.From.Target == assocSetFromEnd &&
                    funcAssocEnd.To.Target == assocSetToEnd)
                {
                    fae = funcAssocEnd;
                    break;
                }
            }

            // create the association end if needed
            if (fae == null)
            {
                fae = new FunctionAssociationEnd(mf, null);
                fae.AssociationSet.SetRefName(assocSet);
                fae.From.SetRefName(assocSetFromEnd);
                fae.To.SetRefName(assocSetToEnd);
                mf.AddAssociationEnd(fae);
                XmlModelHelper.NormalizeAndResolve(fae);
            }

            Debug.Assert(fae != null, "Failed to create the AssocationEnd to house this ScalarProperty");
            if (fae == null)
            {
                throw new ParentItemCreationFailureException();
            }

            // create the SP inside this
            return(CreateFunctionScalarPropertyCommon(fae, entityProperty, parm, version));
        }