Exemple #1
0
 private void TranslatePropertiesOfEntityType(
     ModelEntityType entityType, ViewModelEntityType viewET)
 {
     foreach (var property in entityType.Properties())
     {
         var viewProperty = TranslateProperty(viewET, property);
         Debug.Assert(viewProperty != null);
         if (viewProperty != null)
         {
             viewET.Properties.Add(viewProperty);
         }
     }
 }
Exemple #2
0
        private void TranslateNavigationPropertiesOfEntityType(
            ModelEntityType entityType, ViewModelEntityType viewET)
        {
            var cet = entityType as ConceptualEntityType;

            if (cet != null)
            {
                foreach (var navProp in cet.NavigationProperties())
                {
                    var viewNavProp = TranslateNavigationProperty(viewET, navProp);
                    if (viewNavProp != null)
                    {
                        viewET.NavigationProperties.Add(viewNavProp);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///     Translate model Property into view Property (creates a view Property if not yet created)
        /// </summary>
        /// <param name="viewEntityType"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        private ViewModelProperty TranslateProperty(ViewModelEntityType viewEntityType, ModelProperty property)
        {
            var viewProperty =
                ModelToDesignerModelXRef.GetNewOrExisting(EditingContext, property, viewEntityType.Partition) as ViewModelProperty;
            var scalarProperty = viewProperty as ScalarProperty;

            if (scalarProperty != null)
            {
                // flag if we are part of the key
                scalarProperty.EntityKey = property.IsKeyProperty;
            }

            // set the other properties if they aren't null
            if (property.LocalName.Value != null)
            {
                viewProperty.Name = property.LocalName.Value;
            }

            viewProperty.Type = property.TypeName;

            return(viewProperty);
        }
Exemple #4
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;
        }
        /// <summary>
        ///     Translate model Property into view Property (creates a view Property if not yet created)
        /// </summary>
        /// <param name="viewEntityType"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        private ViewModelProperty TranslateProperty(ViewModelEntityType viewEntityType, ModelProperty property)
        {
            var viewProperty =
                ModelToDesignerModelXRef.GetNewOrExisting(EditingContext, property, viewEntityType.Partition) as ViewModelProperty;
            var scalarProperty = viewProperty as ScalarProperty;
            if (scalarProperty != null)
            {
                // flag if we are part of the key
                scalarProperty.EntityKey = property.IsKeyProperty;
            }

            // set the other properties if they aren't null
            if (property.LocalName.Value != null)
            {
                viewProperty.Name = property.LocalName.Value;
            }

            viewProperty.Type = property.TypeName;

            return viewProperty;
        }
        private void TranslateNavigationPropertiesOfEntityType(
            ModelEntityType entityType, ViewModelEntityType viewET)
        {
            var cet = entityType as ConceptualEntityType;

            if (cet != null)
            {
                foreach (var navProp in cet.NavigationProperties())
                {
                    var viewNavProp = TranslateNavigationProperty(viewET, navProp);
                    if (viewNavProp != null)
                    {
                        viewET.NavigationProperties.Add(viewNavProp);
                    }
                }
            }
        }
 private void TranslatePropertiesOfEntityType(
     ModelEntityType entityType, ViewModelEntityType viewET)
 {
     foreach (var property in entityType.Properties())
     {
         var viewProperty = TranslateProperty(viewET, property);
         Debug.Assert(viewProperty != null);
         if (viewProperty != null)
         {
             viewET.Properties.Add(viewProperty);
         }
     }
 }