src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/CustomSerializer/EntityModelToDslModelTranslatorStrategy.cs
/// <summary>
///     Translate model NavigationProperty into view NavigationProperty (creates a view NavigationProperty if not yet created)
/// </summary>
Translate model NavigationProperty into view NavigationProperty (creates a view NavigationProperty if not yet created)
Translate model NavigationProperty into view NavigationProperty ( creates a view NavigationProperty if not yet created )
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;
                if (association != null)
                {
                    viewNavProp.Association = association;
                    if (viewEntityType == association.SourceEntityType
                        && ((association.SourceEntityType == association.TargetEntityType && association.SourceNavigationProperty == null)
                            || (association.SourceEntityType != association.TargetEntityType)))
                    {
                        association.SourceNavigationProperty = viewNavProp;
                    }
                    if (viewEntityType == association.TargetEntityType)
                    {
                        association.TargetNavigationProperty = viewNavProp;
                    }
                }
            }
            return viewNavProp;
        }
private ViewModelNavigationProperty TranslateNavigationProperty ( ViewModelEntityType viewEntityType , ModelNavigationProperty navProp ) { var viewNavProp = ModelToDesignerModelXRef . GetNewOrExisting ( EditingContext , navProp , viewEntityType . Partition ) as ViewModelNavigationProperty ; Debug . Assert ( viewNavProp != null , " " ) ; viewNavProp . Name = navProp . LocalName . Value ; if ( navProp . Relationship . Status == BindingStatus . Known ) { var association = ModelToDesignerModelXRef . GetExisting ( EditingContext , navProp . Relationship . Target , viewEntityType . Partition ) as ViewModelAssociation ; if ( association != null ) { viewNavProp . Association = association ; if ( viewEntityType == association . SourceEntityType && ( ( association . SourceEntityType == association . TargetEntityType && association . SourceNavigationProperty == null ) || ( association . SourceEntityType != association . TargetEntityType ) ) ) { association . SourceNavigationProperty = viewNavProp ; } if ( viewEntityType == association . TargetEntityType ) { association . TargetNavigationProperty = viewNavProp ; } } } return viewNavProp ; }
Translate model NavigationProperty into view NavigationProperty (creates a view NavigationProperty if not yet created)
Translate model NavigationProperty into view NavigationProperty ( creates a view NavigationProperty if not yet created )
// Association might be null here if the related entity does not exist in the current diagram. // 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. // SourceEntityType might be the same as TargetEntityType, so we need to check this as well
viewEntityType
ViewModelEntityType
navProp
ModelNavigationProperty