Ejemplo n.º 1
0
        /// <summary>
        ///     Translate model NavigationProperty into view NavigationProperty (creates a view NavigationProperty if not yet created)
        /// </summary>
        private ViewModelNavigationProperty TranslateNavigationProperty(ViewModelEntityType viewEntityType, ModelNavigationProperty navProp)
        {
            var viewNavProp =
                ModelToDesignerModelXRef.GetNewOrExisting(EditingContext, navProp, viewEntityType.Partition) as ViewModelNavigationProperty;

            Debug.Assert(viewNavProp != null, "Expected non-null navigation property");
            viewNavProp.Name = navProp.LocalName.Value;

            if (navProp.Relationship.Status == BindingStatus.Known)
            {
                var association =
                    ModelToDesignerModelXRef.GetExisting(EditingContext, navProp.Relationship.Target, viewEntityType.Partition) as
                    ViewModelAssociation;
                // Association might be null here if the related entity does not exist in the current diagram.

                if (association != null)
                {
                    viewNavProp.Association = association;

                    // On a self-relationship case, we ensure that the Source and Target NavProps are not set with the same value.
                    // The source is set first only if SourceEntity == TargetEntityType and the Source navprop has not been set yet. The other case would be
                    // if this is not a self-relationship.
                    if (viewEntityType == association.SourceEntityType &&
                        ((association.SourceEntityType == association.TargetEntityType && association.SourceNavigationProperty == null) ||
                         (association.SourceEntityType != association.TargetEntityType)))
                    {
                        association.SourceNavigationProperty = viewNavProp;
                    }

                    // SourceEntityType might be the same as TargetEntityType, so we need to check this as well
                    if (viewEntityType == association.TargetEntityType)
                    {
                        association.TargetNavigationProperty = viewNavProp;
                    }
                }
            }
            return(viewNavProp);
        }
        /// <summary>
        ///     Translate model NavigationProperty into view NavigationProperty (creates a view NavigationProperty if not yet created)
        /// </summary>
        private ViewModelNavigationProperty TranslateNavigationProperty(ViewModelEntityType viewEntityType, ModelNavigationProperty navProp)
        {
            var viewNavProp =
                ModelToDesignerModelXRef.GetNewOrExisting(EditingContext, navProp, viewEntityType.Partition) as ViewModelNavigationProperty;

            Debug.Assert(viewNavProp != null, "Expected non-null navigation property");
            viewNavProp.Name = navProp.LocalName.Value;

            if (navProp.Relationship.Status == BindingStatus.Known)
            {
                var association =
                    ModelToDesignerModelXRef.GetExisting(EditingContext, navProp.Relationship.Target, viewEntityType.Partition) as
                    ViewModelAssociation;
                // Association might be null here if the related entity does not exist in the current diagram.

                if (association != null)
                {
                    viewNavProp.Association = association;

                    // On a self-relationship case, we ensure that the Source and Target NavProps are not set with the same value.
                    // The source is set first only if SourceEntity == TargetEntityType and the Source navprop has not been set yet. The other case would be
                    // if this is not a self-relationship.
                    if (viewEntityType == association.SourceEntityType
                        && ((association.SourceEntityType == association.TargetEntityType && association.SourceNavigationProperty == null)
                            || (association.SourceEntityType != association.TargetEntityType)))
                    {
                        association.SourceNavigationProperty = viewNavProp;
                    }

                    // SourceEntityType might be the same as TargetEntityType, so we need to check this as well
                    if (viewEntityType == association.TargetEntityType)
                    {
                        association.TargetNavigationProperty = viewNavProp;
                    }
                }
            }
            return viewNavProp;
        }