/// <summary>
        /// Creates two navigation properties representing an association between two entity types.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <param name="partnerInfo">Information to create the partner navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public static EdmNavigationProperty CreateNavigationPropertyWithPartner(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");
            EdmUtil.CheckArgumentNull(partnerInfo, "partnerInfo");
            EdmUtil.CheckArgumentNull(partnerInfo.Name, "partnerInfo.Name");
            EdmUtil.CheckArgumentNull(partnerInfo.Target, "partnerInfo.Target");

            EdmNavigationProperty end1 = new EdmNavigationProperty(
                partnerInfo.Target,
                propertyInfo.Name,
                CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"),
                propertyInfo.DependentProperties,
                propertyInfo.PrincipalProperties,
                propertyInfo.ContainsTarget,
                propertyInfo.OnDelete);

            EdmNavigationProperty end2 = new EdmNavigationProperty(
                propertyInfo.Target,
                partnerInfo.Name,
                CreateNavigationPropertyType(partnerInfo.Target, partnerInfo.TargetMultiplicity, "partnerInfo.TargetMultiplicity"),
                partnerInfo.DependentProperties,
                partnerInfo.PrincipalProperties,
                partnerInfo.ContainsTarget,
                partnerInfo.OnDelete);

            end1.SetPartner(end2, new EdmPathExpression(end2.Name));
            end2.SetPartner(end1, new EdmPathExpression(end1.Name));
            return(end1);
        }
        /// <summary>
        /// Creates two navigation properties representing an association between two entity types.
        /// </summary>
        /// <param name="propertyName">Navigation property name.</param>
        /// <param name="propertyType">Type of the navigation property.</param>
        /// <param name="dependentProperties">Dependent properties of the navigation source.</param>
        /// <param name="principalProperties">Principal properties of the navigation source.</param>
        /// <param name="containsTarget">A value indicating whether the navigation source logically contains the navigation target.</param>
        /// <param name="onDelete">Action to take upon deletion of an instance of the navigation source.</param>
        /// <param name="partnerPropertyName">Navigation partner property name.</param>
        /// <param name="partnerPropertyType">Type of the navigation partner property.</param>
        /// <param name="partnerDependentProperties">Dependent properties of the navigation target.</param>
        /// <param name="partnerPrincipalProperties">Principal properties of the navigation target.</param>
        /// <param name="partnerContainsTarget">A value indicating whether the navigation target logically contains the navigation source.</param>
        /// <param name="partnerOnDelete">Action to take upon deletion of an instance of the navigation target.</param>
        /// <returns>Navigation property.</returns>
        public static EdmNavigationProperty CreateNavigationPropertyWithPartner(
            string propertyName,
            IEdmTypeReference propertyType,
            IEnumerable <IEdmStructuralProperty> dependentProperties,
            IEnumerable <IEdmStructuralProperty> principalProperties,
            bool containsTarget,
            EdmOnDeleteAction onDelete,
            string partnerPropertyName,
            IEdmTypeReference partnerPropertyType,
            IEnumerable <IEdmStructuralProperty> partnerDependentProperties,
            IEnumerable <IEdmStructuralProperty> partnerPrincipalProperties,
            bool partnerContainsTarget,
            EdmOnDeleteAction partnerOnDelete)
        {
            EdmUtil.CheckArgumentNull(propertyName, "propertyName");
            EdmUtil.CheckArgumentNull(propertyType, "propertyType");
            EdmUtil.CheckArgumentNull(partnerPropertyName, "partnerPropertyName");
            EdmUtil.CheckArgumentNull(partnerPropertyType, "partnerPropertyType");

            IEdmEntityType declaringType = GetEntityType(partnerPropertyType);

            if (declaringType == null)
            {
                throw new ArgumentException(Strings.Constructable_EntityTypeOrCollectionOfEntityTypeExpected, "partnerPropertyType");
            }

            IEdmEntityType partnerDeclaringType = GetEntityType(propertyType);

            if (partnerDeclaringType == null)
            {
                throw new ArgumentException(Strings.Constructable_EntityTypeOrCollectionOfEntityTypeExpected, "propertyType");
            }

            EdmNavigationProperty end1 = new EdmNavigationProperty(
                declaringType,
                propertyName,
                propertyType,
                dependentProperties,
                principalProperties,
                containsTarget,
                onDelete);

            EdmNavigationProperty end2 = new EdmNavigationProperty(
                partnerDeclaringType,
                partnerPropertyName,
                partnerPropertyType,
                partnerDependentProperties,
                partnerPrincipalProperties,
                partnerContainsTarget,
                partnerOnDelete);

            end1.SetPartner(end2, new EdmPathExpression(end2.Name));
            end2.SetPartner(end1, new EdmPathExpression(end1.Name));
            return(end1);
        }
Exemple #3
0
 public void SetNavigationPropertyPartner(
     EdmNavigationProperty navigationProperty,
     IEdmPathExpression navigationPropertyPath,
     EdmNavigationProperty partnerNavigationProperty,
     IEdmPathExpression partnerNavigationPropertyPath)
 {
     Debug.Assert(
         this.IsOnSameTypeHierarchyLineWith(navigationProperty.DeclaringType),
         "Nav. property is not defined on this or a derived entity type.");
     navigationProperty.SetPartner(partnerNavigationProperty, partnerNavigationPropertyPath);
     if (partnerNavigationProperty.DeclaringType is IEdmEntityType)
     {
         partnerNavigationProperty.SetPartner(navigationProperty, navigationPropertyPath);
     }
 }