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)); }