internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return(null);
            }

            var parentItem = parent.Parent as EFElement;

            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            // some asserts to verify we're using this name normalizer in the correct context

            Debug.Assert(
                parentItem.GetParentOfType(typeof(ComplexProperty)) == null,
                "Use the PropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionComplexProperty)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(EntityTypeMapping)) == null,
                "Use the PropertyMappingNameNormalizer or FunctionPropertyMappingNameNormalizer to normalize children of "
                + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(AssociationSetMapping)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);
            Debug.Assert(
                parentItem.GetParentOfType(typeof(EndProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            //
            // try to normalize for a FunctionImportTypeMapping
            //
            var fitm = parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) as FunctionImportTypeMapping;

            if (fitm != null)
            {
                if (fitm.TypeName.Status == BindingStatus.Known)
                {
                    var symbol = new Symbol(fitm.TypeName.Target.NormalizedName, refName);
                    return(new NormalizedName(symbol, null, null, refName));
                }
            }

            return(new NormalizedName(new Symbol(refName), null, null, refName));
        }
示例#2
0
        // <summary>
        //     NOTE: The association set mapping view model doesn't keep a reference to the mapping model item. Instead, it
        //     keeps it to the AssociationSet and then it can find the AssociationSetMapping as an anti-dep.  We don't need to clear
        //     or set the ModelItem property.
        // </summary>
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "The context argument cannot be null");
            Debug.Assert(AssociationSet.AssociationSetMapping == null, "Don't call this method if we already have a mapping");
            Debug.Assert(underlyingModelItem != null, "The underlyingModelItem cannot be null");
            var storeEntityType = underlyingModelItem as EntityType;

            Debug.Assert(
                storeEntityType != null,
                "underlyingModelItem must be of type EntityType, actual type = " + underlyingModelItem.GetType().FullName);
            Debug.Assert(!storeEntityType.EntityModel.IsCSDL, "The storageEntityType must not be a CSDL EntityType");

            Context = context;

            // create a context if we weren't passed one
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateAssociationSetMapping);
            }

            // create the item
            var cmd1 = new CreateAssociationSetMappingCommand(MappingAssociation.Association, storeEntityType);

            // now try and do some match ups by name
            var cmd2 = new DelegateCommand(
                () =>
            {
                Parent.AddChild(this);

                foreach (var child in Children)
                {
                    var end = child as MappingAssociationSetEnd;
                    if (end != null)
                    {
                        foreach (var child2 in end.Children)
                        {
                            var mesp = child2 as MappingEndScalarProperty;
                            if (mesp != null)
                            {
                                var tableColumn =
                                    MappingAssociationSet.StorageEntityType.GetFirstNamedChildByLocalName(mesp.Property, true) as
                                    Property;
                                if (tableColumn != null)
                                {
                                    mesp.CreateModelItem(cpc, _context, tableColumn);
                                }
                            }
                        }
                    }
                }
            });

            // now make the change
            var cp = new CommandProcessor(cpc);

            cp.EnqueueCommand(cmd1);
            cp.EnqueueCommand(cmd2);
            cp.Invoke();
        }
示例#3
0
        // TODO - make this private, and remove the need to pass in the type to GetNew()/GetNewOrExisting().
        protected override Type GetViewModelTypeForEFlement(EFElement efElement)
        {
            if (!IsDisplayedInExplorer(efElement))
            {
                return(null);
            }

            var efElementType = efElement.GetType();

            Type explorerType = null;

            _modelType2ExplorerViewModelType.TryGetValue(efElementType, out explorerType);

            // Get correct view-model type for a c-side or s-side entity type.
            if (explorerType == null)
            {
                var assoc = efElement as Association;
                if (assoc != null)
                {
                    if (assoc.EntityModel.IsCSDL)
                    {
                        explorerType = typeof(ExplorerConceptualAssociation);
                    }
                    else
                    {
                        explorerType = typeof(ExplorerStorageAssociation);
                    }
                }
            }

            Debug.Assert(explorerType != null, "Unable to find explorer type for efobject type " + efElementType);

            return(explorerType);
        }
示例#4
0
 protected virtual void InsertChild(EFElement efElementToInsert)
 {
     throw new InvalidOperationException(
               string.Format(
                   CultureInfo.CurrentCulture,
                   Resources.BadInsertBadChildType, efElementToInsert.GetType().FullName, GetType().FullName));
 }
示例#5
0
        internal override ExplorerEFElement GetParentNodeForElement(EFElement childElement)
        {
            Debug.Assert(childElement != null, "on ExplorerEFElement with name " + Name + " received null child");
            var childElementType = childElement.GetType();

            if (typeof(StorageEntityType) == childElementType)
            {
                return(_typesGhostNode);
            }
            else if (typeof(Association) == childElementType)
            {
                return(_assocsGhostNode);
            }
            else if (typeof(Function) == childElementType)
            {
                return(_funcsGhostNode);
            }
            else if (typeof(StorageEntityContainer) == childElementType)
            {
                return(this);
            }
            else
            {
                Debug.Fail(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.BadChildForParentException, GetType().FullName, childElementType.FullName));
                return(null);
                // TODO: we need to provide a general exception-handling mechanism and replace the above Assert()
                // by e.g. the excepiton below
                // throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                //     Resources.BadChildForParentException, this.GetType().FullName, childElementType.FullName));
            }
        }
        internal override ExplorerEFElement GetParentNodeForElement(EFElement childElement)
        {
            Debug.Assert(childElement != null, "GetParentNodeForElement on ExplorerEFElement with name " + Name + " received null child");
            Debug.Assert(
                ModelItem == childElement.Parent, "GetParentNodeForElement - underlying model element with identity " +
                ModelItem.Identity + " is not the same as the child element's parent, which has identity "
                + childElement.Parent.Identity);
            var childElementType = childElement.GetType();

            if (typeof(ConceptualEntitySet) == childElementType)
            {
                return(_entitySetsGhostNode);
            }
            else if (typeof(AssociationSet) == childElementType)
            {
                return(_assocSetsGhostNode);
            }
            else if (typeof(FunctionImport) == childElementType)
            {
                // if asked what FunctionImport parent node is redirect to the parent (i.e. the ConceptulaEntityModel)
                // This is because, for FunctionImports, we are not using the same parent-child relationship in the
                // View-Model that we are in the Model
                return(Parent.GetParentNodeForElement(childElement));
            }
            else
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Resources.BadChildForParentException, GetType().FullName, childElementType.FullName));
            }
        }
示例#7
0
 internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
 {
     Debug.Assert(underlyingModelItem != null, "underlyingModelItem argument cannot be null");
     if (underlyingModelItem != null)
     {
         var entityProperty = underlyingModelItem as Property;
         Debug.Assert(
             entityProperty != null,
             "underlyingModelItem argument was of type " + underlyingModelItem.GetType().FullName + ", should be Property");
         if (entityProperty != null)
         {
             var properties = new List <Property>(1);
             properties.Add(entityProperty);
             CreateModelItem(cpc, context, properties);
         }
     }
 }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var parentItem = parent.Parent as EFElement;
            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            // some asserts to verify we're using this name normalizer in the correct context

            Debug.Assert(
                parentItem.GetParentOfType(typeof(ComplexProperty)) == null,
                "Use the PropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionComplexProperty)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(EntityTypeMapping)) == null,
                "Use the PropertyMappingNameNormalizer or FunctionPropertyMappingNameNormalizer to normalize children of "
                + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(AssociationSetMapping)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);
            Debug.Assert(
                parentItem.GetParentOfType(typeof(EndProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            //
            // try to normalize for a FunctionImportTypeMapping
            //
            var fitm = parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) as FunctionImportTypeMapping;
            if (fitm != null)
            {
                if (fitm.TypeName.Status == BindingStatus.Known)
                {
                    var symbol = new Symbol(fitm.TypeName.Target.NormalizedName, refName);
                    return new NormalizedName(symbol, null, null, refName);
                }
            }

            return new NormalizedName(new Symbol(refName), null, null, refName);
        }
        private static ExplorerEFElement GetNewOrExisting(
            EditingContext context, EFElement efElement, ExplorerEFElement parent, Type viewModelType, bool mustNotExist)
        {
            var xref   = GetModelToBrowserModelXRef(context);
            var result = xref.GetExisting(efElement);

            if (result != null)
            {
                if (mustNotExist)
                {
                    Debug.Fail(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            Resources.BadInsertChildAlreadyExists, efElement.GetType().FullName, parent.GetType().FullName));
                    return(null);
                    // TODO: we need to provide a general exception-handling mechanism and replace the above Assert()
                    // by e.g. the excepiton below
                    // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.BadInsertChildAlreadyExists, efElement.GetType().FullName, parent.GetType().FullName));
                }
                else
                {
                    result.Parent = parent;
                }
            }
            else
            {
                if (viewModelType != null)
                {
                    if (!xref.IsDisplayedInExplorerProtected(efElement))
                    {
                        Debug.Fail(
                            "Attempting to create an ExplorerEFElement of type " + viewModelType.FullName +
                            " based on an EFElement which is not displayed in the Explorer " + efElement.ToPrettyString());
                        return(null);
                    }

                    result = Activator.CreateInstance(viewModelType, context, efElement, parent) as ExplorerEFElement;
                    xref.Add(efElement, result);
                }
            }

            return(result);
        }
示例#10
0
        // <summary>
        //     Helper method that determine whether an EFElement is represented in model browser.
        // </summary>
        internal static bool IsDisplayedInExplorer(EFElement efElement)
        {
            // If efElement type is StorageEntityContainer or EFDesignerInfoRoot, don't display it in Model Browser.
            // Note: GetParentOfType() will also return true if self is of passed-in type.
            if (null != efElement.GetParentOfType(typeof(StorageEntityContainer)))
            {
                return(false);
            }
            // We do not display Enum type members
            else if (efElement is EnumTypeMember)
            {
                return(false);
            }
            // For any Designer objects, check whether the map between the EFElement and ExplorerEFElement exists.
            else if (null != efElement.GetParentOfType(typeof(EFDesignerInfoRoot)))
            {
                return(_modelType2ExplorerViewModelType.ContainsKey(efElement.GetType()));
            }

            return(true);
        }
        internal override ExplorerEFElement GetParentNodeForElement(EFElement childElement)
        {
            Debug.Assert(
                childElement != null,
                "GetParentNodeForElement on ExplorerEFElement with name " + Name + " received null child");

            var childElementType = childElement.GetType();

            if (typeof(ConceptualEntityType) == childElementType)
            {
                return(_typesGhostNode);
            }
            if (typeof(ComplexType) == childElementType)
            {
                return(_complexTypesGhostNode);
            }
            else if (typeof(EnumType) == childElementType)
            {
                return(_enumTypesGhostNode);
            }
            else if (typeof(Association) == childElementType)
            {
                return(_assocsGhostNode);
            }
            else if (typeof(FunctionImport) == childElementType)
            {
                return(_funcImportsGhostNode);
            }
            else if (typeof(ConceptualEntityContainer) == childElementType)
            {
                return(this);
            }
            else
            {
                throw new InvalidOperationException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Resources.BadChildForParentException, GetType().FullName, childElementType.FullName));
            }
        }
        internal static FunctionScalarProperty CreateFunctionScalarPropertyCommon(
            EFElement parent, Property property, Parameter parm, string version)
        {
            var fsp = new FunctionScalarProperty(parent, null);

            fsp.Name.SetRefName(property);
            fsp.ParameterName.SetRefName(parm);
            if (string.IsNullOrEmpty(version) == false)
            {
                fsp.Version.Value = version;
            }

            var mf  = parent as ModificationFunction;
            var fae = parent as FunctionAssociationEnd;
            var fcp = parent as FunctionComplexProperty;

            if (mf != null)
            {
                mf.AddScalarProperty(fsp);
            }
            else if (fae != null)
            {
                fae.AddScalarProperty(fsp);
            }
            else if (fcp != null)
            {
                fcp.AddScalarProperty(fsp);
            }
            else
            {
                Debug.Fail(
                    "Unknown parent type (" + parent.GetType().FullName
                    + ") sent to CreateFunctionScalarPropertyCommand.CreateFunctionScalarPropertyCommon()");
            }

            XmlModelHelper.NormalizeAndResolve(fsp);

            return(fsp);
        }
示例#13
0
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return(null);
            }

            var parentItem = parent.Parent as EFElement;

            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            // shouldn't use this normalizer for a ComplexProperty
            Debug.Assert(
                parentItem.GetParentOfType(typeof(ComplexProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            // shouldn't use this normalizer for an AssociationSetMapping
            Debug.Assert(
                parentItem.GetParentOfType(typeof(AssociationSetMapping)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);
            Debug.Assert(
                parentItem.GetParentOfType(typeof(EndProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            // shouldn't use this normalizer for a FunctionImportTypeMapping
            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) == null,
                "Use the FunctionImportPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            NormalizedName normalizedName = null;

            //
            // try to normalize for a FunctionComplexProperty
            //
            var fcp = parentItem.GetParentOfType(typeof(FunctionComplexProperty)) as FunctionComplexProperty;

            normalizedName = NormalizeNameRelativeToFunctionComplexProperty(fcp, refName);
            if (normalizedName != null)
            {
                return(normalizedName);
            }

            //
            // try to normalize for an EntityTypeMapping with no FunctionAssociationEnd
            //
            var etm = parentItem.GetParentOfType(typeof(EntityTypeMapping)) as EntityTypeMapping;
            var fae = parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) as FunctionAssociationEnd;

            if (fae == null)
            {
                normalizedName = PropertyMappingNameNormalizer.NormalizePropertyNameRelativeToEntityTypeMapping(etm, parent, refName);
                if (normalizedName != null)
                {
                    return(normalizedName);
                }
            }
            else
            {
                //
                // try to normalize for a FunctionAssociationEnd
                //
                normalizedName = NormalizePropertyNameRelativeToFunctionAssociationEnd(fae, parent, refName);
                if (normalizedName != null)
                {
                    return(normalizedName);
                }
            }

            //
            //  Default case...
            //
            return(new NormalizedName(new Symbol(refName), null, null, refName));
        }
        internal static FunctionScalarProperty CreateFunctionScalarPropertyCommon(
            EFElement parent, Property property, Parameter parm, string version)
        {
            var fsp = new FunctionScalarProperty(parent, null);
            fsp.Name.SetRefName(property);
            fsp.ParameterName.SetRefName(parm);
            if (string.IsNullOrEmpty(version) == false)
            {
                fsp.Version.Value = version;
            }

            var mf = parent as ModificationFunction;
            var fae = parent as FunctionAssociationEnd;
            var fcp = parent as FunctionComplexProperty;
            if (mf != null)
            {
                mf.AddScalarProperty(fsp);
            }
            else if (fae != null)
            {
                fae.AddScalarProperty(fsp);
            }
            else if (fcp != null)
            {
                fcp.AddScalarProperty(fsp);
            }
            else
            {
                Debug.Fail(
                    "Unknown parent type (" + parent.GetType().FullName
                    + ") sent to CreateFunctionScalarPropertyCommand.CreateFunctionScalarPropertyCommon()");
            }

            XmlModelHelper.NormalizeAndResolve(fsp);

            return fsp;
        }
示例#15
0
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "context must not be null");
            Debug.Assert(Condition == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(MappingStorageEntityType.StorageEntityType != null, "The parent item isn't set up correctly");
            Debug.Assert(underlyingModelItem != null, "underlyingModelItem must not be null");

            var tableColumn = underlyingModelItem as Property;

            Debug.Assert(
                tableColumn != null, "underlyingModelItem must be of type Property, actual type = " + underlyingModelItem.GetType().FullName);

            // store this off in case we have recover the condition later (if it moves to another ETM on us)
            _modelItemColumnName = tableColumn.LocalName.Value;

            Context = context;

            // local shortcuts
            EntityType entityType = MappingConceptualEntityType.ConceptualEntityType;

            // create a context if we weren't passed one
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateCondition);
            }

            // use empty string as a default condition value
            var cmd = new CreateFragmentConditionCommand(entityType, tableColumn, null, String.Empty);

            // set up our post event to fix up the view model
            cmd.PostInvokeEvent += (o, eventsArgs) =>
            {
                var cond = cmd.CreatedCondition;
                Debug.Assert(cond != null, "cmd failed to create Condition");

                // fix up our view model
                ModelItem = cond;
                Parent.AddChild(this);
            };

            try
            {
                // now make the change
                var cp = new CommandProcessor(cpc, cmd);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                Parent.RemoveChild(this);

                throw;
            }
        }
示例#16
0
        internal static MappingEFElement GetNewOrExisting(EditingContext context, EFElement modelElement, MappingEFElement parent)
        {
            MappingEFElement result;

            var xref = GetModelToMappingModelXRef(context);

            result = xref.GetExisting(modelElement);
            if (result != null)
            {
                result.Parent = parent;
            }
            else
            {
                Type viewModelType;
                ModelTypeToViewModelType.TryGetValue(modelElement.GetType(), out viewModelType);
                if (viewModelType == null)
                {
                    // try the base class type
                    ModelTypeToViewModelType.TryGetValue(modelElement.GetType().BaseType, out viewModelType);
                }

                if (viewModelType != null)
                {
                    result = Activator.CreateInstance(viewModelType, context, modelElement, parent) as MappingEFElement;
                    xref.Add(modelElement, result);
                }
                else
                {
                    // implement a special case for entity type
                    // create the correct C- or S-space entity type in our view model
                    var entityType = modelElement as EntityType;
                    if (entityType != null)
                    {
                        var mappingDetailsInfo = context.Items.GetValue <MappingDetailsInfo>();
                        if (mappingDetailsInfo.EntityMappingMode == EntityMappingModes.Tables)
                        {
                            var entityModel = entityType.Parent as BaseEntityModel;
                            Debug.Assert(
                                entityModel != null,
                                "entityType's parent should be an EntityModel but received type "
                                + (entityType.Parent == null ? "NULL" : entityType.Parent.GetType().FullName));

                            if (entityModel.IsCSDL)
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingConceptualEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                            else
                            {
                                result =
                                    Activator.CreateInstance(typeof(MappingStorageEntityType), context, modelElement, parent) as
                                    MappingEFElement;
                            }
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingFunctionEntityType), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }

                    // special case for scalar properties
                    var scalarProperty = modelElement as ScalarProperty;
                    if (scalarProperty != null)
                    {
                        if (scalarProperty.Parent is MappingFragment ||
                            scalarProperty.Parent is ComplexProperty)
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingScalarProperty), context, modelElement, parent) as MappingEFElement;
                        }
                        else
                        {
                            result =
                                Activator.CreateInstance(typeof(MappingEndScalarProperty), context, modelElement, parent) as
                                MappingEFElement;
                        }
                        xref.Add(modelElement, result);
                    }
                }
            }

            return(result);
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var parentItem = parent.Parent as EFElement;
            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            // shouldn't use this normalizer for a ComplexProperty
            Debug.Assert(
                parentItem.GetParentOfType(typeof(ComplexProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            // shouldn't use this normalizer for an AssociationSetMapping
            Debug.Assert(
                parentItem.GetParentOfType(typeof(AssociationSetMapping)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);
            Debug.Assert(
                parentItem.GetParentOfType(typeof(EndProperty)) == null,
                "Use the PropertyNameNormalizer to normalize children of " + parent.GetType().FullName);

            // shouldn't use this normalizer for a FunctionImportTypeMapping
            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) == null,
                "Use the FunctionImportPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            NormalizedName normalizedName = null;

            //
            // try to normalize for a FunctionComplexProperty
            //
            var fcp = parentItem.GetParentOfType(typeof(FunctionComplexProperty)) as FunctionComplexProperty;
            normalizedName = NormalizeNameRelativeToFunctionComplexProperty(fcp, refName);
            if (normalizedName != null)
            {
                return normalizedName;
            }

            //
            // try to normalize for an EntityTyepMapping with no FunctionAssociationEnd 
            //
            var etm = parentItem.GetParentOfType(typeof(EntityTypeMapping)) as EntityTypeMapping;
            var fae = parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) as FunctionAssociationEnd;
            if (fae == null)
            {
                normalizedName = ProperyMappingNameNormalizer.NormalizePropertyNameRelativeToEntityTypeMapping(etm, parent, refName);
                if (normalizedName != null)
                {
                    return normalizedName;
                }
            }
            else
            {
                //
                // try to normalize for a FunctionAssociationEnd
                //
                normalizedName = NormalizePropertyNameRelativeToFunctionAssociationEnd(fae, parent, refName);
                if (normalizedName != null)
                {
                    return normalizedName;
                }
            }

            //
            //  Default case...
            //
            return new NormalizedName(new Symbol(refName), null, null, refName);
        }
示例#18
0
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "null context");

            Debug.Assert(Function == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(MappingFunctionEntityType.EntityType != null, "The parent item isn't set up correctly");

            Debug.Assert(underlyingModelItem != null, "null underlyingModelItem");

            var function = underlyingModelItem as Function;

            Debug.Assert(
                function != null, "underlyingModelItem must be of type Function, actual type = " + underlyingModelItem.GetType().FullName);
            Debug.Assert(!function.EntityModel.IsCSDL, "The function must be in the SSDL");

            Context = context;

            // create a context if we weren't passed one
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateFunctionMapping);
            }

            // create the commands
            var cmd = new CreateFunctionMappingCommand(MappingFunctionEntityType.EntityType, function, null, _functionType);

            // set up our post event to fix up the view model
            cmd.PostInvokeEvent += (o, eventsArgs) =>
            {
                var mf = cmd.ModificationFunction;
                Debug.Assert(mf != null, "null ModificationFunction");

                // fix up our view model
                ModelItem = mf;
                // The parent item for the function mapping view model always has 3 children; insert, update and delete items.  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.
                // Calling this.Parent.AddChild(this) here would make the parent think it had a new child instead of updating the existing one -
                // so it is correct to _not_ call it here.
            };

            var cmd2 = new DelegateCommand(
                () =>
            {
                var mf = ModificationFunction;
                Debug.Assert(
                    mf != null,
                    "Null ModificationFunction when trying to create view-model dummy nodes in MappingModificationFunctionMapping.CreateModelItem()");

                if (mf != null)
                {
                    //set up _properties and _resultBindings here as they are dummy ViewModel nodes
                    // (i.e. don't correspond to any underlying ModelItem)
                    _properties     = new MappingFunctionScalarProperties(context, mf, this);
                    _resultBindings = new MappingResultBindings(context, mf, this);
                    _properties.Parent.AddChild(_properties);
                    _resultBindings.Parent.AddChild(_resultBindings);

                    // now ensure _properties scalar properties children have been calculated
                    // (this creates scalar properties with just the column info
                    // since this ModificationFunction has not yet been mapped)
                    _properties.LoadScalarProperties();

                    // now try and do some match ups between the function and the entity
                    var mappedEntityType = MappingFunctionEntityType.EntityType as ConceptualEntityType;

                    Debug.Assert(
                        MappingFunctionEntityType.EntityType == null || mappedEntityType != null,
                        "EntityType is not ConceptualEntityType");

                    if (mappedEntityType != null)
                    {
                        foreach (var mfsp in _properties.ScalarProperties)
                        {
                            // Try to do some auto-matching of the sproc's parameters to the EntityType's properties.
                            // Search for a property in the mapped EntityType's inheritance hierarchy that matches the
                            // parameter's name. First search this EntityType (both its scalar and complex properties),
                            // then search its parents scalar and complex properties and so on up the hierarchy
                            var propNameToSearchFor = mfsp.StoreParameter.LocalName.Value;
                            var propList            = new List <Property>();
                            var entityTypeToSearch  = mappedEntityType;
                            // reset this back to the mapped EntityType each time through the loop
                            while (entityTypeToSearch != null &&
                                   false
                                   == ModelHelper.FindScalarPropertyPathByLocalName(
                                       entityTypeToSearch, propNameToSearchFor, out propList))
                            {
                                if (entityTypeToSearch.BaseType == null)
                                {
                                    // safety code - this should not happen but will prevent an infinite loop if it does
                                    entityTypeToSearch = null;
                                }
                                else
                                {
                                    entityTypeToSearch = entityTypeToSearch.BaseType.Target;
                                }
                            }

                            // if propList is still empty that means we did not find a match - so leave the parameter unmapped
                            if (propList.Count > 0)
                            {
                                mfsp.CreateModelItem(cpc, _context, propList);
                            }
                        }
                    }
                }
            });

            try
            {
                // now make the change
                var cp = new CommandProcessor(cpc);
                cp.EnqueueCommand(cmd);
                cp.EnqueueCommand(cmd2);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                ClearChildren();

                throw;
            }
        }
示例#19
0
        internal override void CreateModelItem(CommandProcessorContext cpc, EditingContext context, EFElement underlyingModelItem)
        {
            Debug.Assert(context != null, "The context argument cannot be null");
            Debug.Assert(StorageEntityType == null, "Don't call this method if we already have a ModelItem");
            Debug.Assert(MappingConceptualEntityType.ConceptualEntityType != null, "The parent item isn't set up correctly");
            Debug.Assert(underlyingModelItem != null, "The underlyingModelItem cannot be null");
            var storeEntityType = underlyingModelItem as EntityType;

            Debug.Assert(
                storeEntityType != null,
                "underlyingModelItem must be of type EntityType, actual type = " + underlyingModelItem.GetType().FullName);
            Debug.Assert(storeEntityType.EntityModel.IsCSDL == false, "The storageEntityType must not be a CSDL EntityType");

            Context = context;
            ColumnMappings.Context = context;

            // create a context if we weren't passed one
            if (cpc == null)
            {
                cpc = new CommandProcessorContext(
                    Context, EfiTransactionOriginator.MappingDetailsOriginatorId, Resources.Tx_CreateMappingFragment);
            }

            // create the MappingFragment - if we already have a default EntityTypeMapping then just add
            // the MappingFragment to that mapping, otherwise if we already have an IsTypeOf
            // EntityTypeMapping then add the MappingFragment to that, otherwise create an IsTypeOf
            // EntityTypeMapping and add the MappingFragment to that
            var cet        = MappingConceptualEntityType.ConceptualEntityType;
            var defaultEtm = ModelHelper.FindEntityTypeMapping(cpc, cet, EntityTypeMappingKind.Default, false);
            var etmKind    = (defaultEtm == null ? EntityTypeMappingKind.IsTypeOf : EntityTypeMappingKind.Default);
            var cmd        = new CreateMappingFragmentCommand(cet, storeEntityType, etmKind);

            // add post-invoke event to fix up our view model
            cmd.PostInvokeEvent += (o, eventsArgs) =>
            {
                // fix up our view model
                ModelItem = storeEntityType;
                Parent.AddChild(this);

                // assign the table to our container node as well
                ColumnMappings.ModelItem = storeEntityType;

                // now try and do some match ups between the entity and the table
                var mappingStrategy = ModelHelper.DetermineCurrentInheritanceStrategy(cet);
                var topMostBaseType = cet.ResolvableTopMostBaseType;
                foreach (var child in ColumnMappings.Children)
                {
                    var msp = child as MappingScalarProperty;
                    if (msp != null)
                    {
                        List <Property> properties;
                        if (ModelHelper.FindScalarPropertyPathByLocalName(cet, msp.ColumnName, out properties))
                        {
                            msp.CreateModelItem(cpc, _context, properties);
                        }
                        else if (InheritanceMappingStrategy.TablePerType == mappingStrategy
                                 &&
                                 ModelHelper.FindScalarPropertyPathByLocalName(topMostBaseType, msp.ColumnName, out properties))
                        {
                            msp.CreateModelItem(cpc, _context, properties);
                        }
                    }
                }
            };

            try
            {
                // now update the model
                var cp = new CommandProcessor(cpc);
                cp.EnqueueCommand(cmd);
                cp.Invoke();
            }
            catch
            {
                ModelItem = null;
                ColumnMappings.ModelItem = null;
                Parent.RemoveChild(this);
                throw;
            }
        }
示例#20
0
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return(null);
            }

            var parentItem = parent.Parent as EFElement;

            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) == null,
                "Use the FunctionImportPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionComplexProperty)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            NormalizedName normalizedName = null;

            //
            // try to normalize for location in a ComplexProperty
            //
            var cp = parentItem.GetParentOfType(typeof(ComplexProperty)) as ComplexProperty;

            normalizedName = NormalizePropertyNameRelativeToComplexProperty(cp, refName);
            if (normalizedName != null)
            {
                return(normalizedName);
            }

            //
            // try to normalize for an EntityTypeMapping with no FunctionAssociationEnd
            //
            var etm = parentItem.GetParentOfType(typeof(EntityTypeMapping)) as EntityTypeMapping;

            normalizedName = NormalizePropertyNameRelativeToEntityTypeMapping(etm, parent, refName);
            if (normalizedName != null)
            {
                return(normalizedName);
            }

            //
            // try to normalize for an AssociationSetMapping
            //
            var asm = parentItem.GetParentOfType(typeof(AssociationSetMapping)) as AssociationSetMapping;
            var ep  = parentItem.GetParentOfType(typeof(EndProperty)) as EndProperty;

            normalizedName = NormalizePropertyNameRelativeToAssociationSetMapping(asm, ep, parent, refName);
            if (normalizedName != null)
            {
                return(normalizedName);
            }

            if (asm != null)
            {
                var cond = parent as Condition;
                Debug.Assert(
                    cond == null, "It is assumed that Conditions under an AssociationSetMapping cannot have their Name property set.");
            }

            //
            //  Default case...
            //
            return(new NormalizedName(new Symbol(refName), null, null, refName));
        }
        internal static NormalizedName NameNormalizer(EFElement parent, string refName)
        {
            Debug.Assert(parent != null, "parent should not be null");

            if (refName == null)
            {
                return null;
            }

            var parentItem = parent.Parent as EFElement;
            Debug.Assert(parentItem != null, "parent.Parent should be an EFElement");

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionImportTypeMapping)) == null,
                "Use the FunctionImportPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionComplexProperty)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            Debug.Assert(
                parentItem.GetParentOfType(typeof(FunctionAssociationEnd)) == null,
                "Use the FunctionPropertyMappingNameNormalizer to normalize children of " + parent.GetType().FullName);

            NormalizedName normalizedName = null;

            //
            // try to normalize for location in a ComplexProperty
            //
            var cp = parentItem.GetParentOfType(typeof(ComplexProperty)) as ComplexProperty;
            normalizedName = NormalizePropertyNameRelativeToComplexProperty(cp, refName);
            if (normalizedName != null)
            {
                return normalizedName;
            }

            //
            // try to normalize for an EntityTyepMapping with no FunctionAssociationEnd 
            //
            var etm = parentItem.GetParentOfType(typeof(EntityTypeMapping)) as EntityTypeMapping;
            normalizedName = NormalizePropertyNameRelativeToEntityTypeMapping(etm, parent, refName);
            if (normalizedName != null)
            {
                return normalizedName;
            }

            //
            // try to normalize for an AssociationSetMapping
            //
            var asm = parentItem.GetParentOfType(typeof(AssociationSetMapping)) as AssociationSetMapping;
            var ep = parentItem.GetParentOfType(typeof(EndProperty)) as EndProperty;
            normalizedName = NormalizePropertyNameRelativeToAssociationSetMapping(asm, ep, parent, refName);
            if (normalizedName != null)
            {
                return normalizedName;
            }

            if (asm != null)
            {
                var cond = parent as Condition;
                Debug.Assert(
                    cond == null, "It is assumed that Conditions under an AssociationSetMapping cannot have their Name property set.");
            }

            //
            //  Default case...
            //
            return new NormalizedName(new Symbol(refName), null, null, refName);
        }