예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <summary>
        /// Creates and adds a unidirectional navigation property to this type.
        /// </summary>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public EdmNavigationProperty AddUnidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");

            EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationProperty(this, propertyInfo);

            this.AddProperty(property);
            return(property);
        }
예제 #3
0
        /// <summary>
        /// Creates and adds a navigation property to this type and adds its navigation partner to the navigation target type.
        /// </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 EdmNavigationProperty AddBidirectionalNavigation(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");

            EdmEntityType targetType = propertyInfo.Target as EdmEntityType;

            if (targetType == null)
            {
                throw new ArgumentException("propertyInfo.Target", Strings.Constructable_TargetMustBeStock(typeof(EdmEntityType).FullName));
            }

            EdmNavigationProperty property = EdmNavigationProperty.CreateNavigationPropertyWithPartner(propertyInfo, this.FixUpDefaultPartnerInfo(propertyInfo, partnerInfo));

            this.AddProperty(property);
            targetType.AddProperty(property.Partner);
            return(property);
        }
예제 #4
0
        /// <summary>
        /// The purpose of this method is to make sure that some of the <paramref name="partnerInfo"/> fields are set to valid partner defaults.
        /// For example if <paramref name="partnerInfo"/>.Target is null, it will be set to this entity type. If <paramref name="partnerInfo"/>.TargetMultiplicity
        /// is unknown, it will be set to 0..1, etc.
        /// Whenever this method applies new values to <paramref name="partnerInfo"/>, it will return a copy of it (thus won't modify the original).
        /// If <paramref name="partnerInfo"/> is null, a new info object will be produced.
        /// </summary>
        /// <param name="propertyInfo">Primary navigation property info.</param>
        /// <param name="partnerInfo">Partner navigation property info. May be null.</param>
        /// <returns>Partner info.</returns>
        private EdmNavigationPropertyInfo FixUpDefaultPartnerInfo(EdmNavigationPropertyInfo propertyInfo, EdmNavigationPropertyInfo partnerInfo)
        {
            EdmNavigationPropertyInfo partnerInfoOverride = null;

            if (partnerInfo == null)
            {
                partnerInfo = partnerInfoOverride = new EdmNavigationPropertyInfo();
            }

            if (partnerInfo.Name == null)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.Name = (propertyInfo.Name ?? String.Empty) + "Partner";
            }

            if (partnerInfo.Target == null)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.Target = this;
            }

            if (partnerInfo.TargetMultiplicity == EdmMultiplicity.Unknown)
            {
                if (partnerInfoOverride == null)
                {
                    partnerInfoOverride = partnerInfo.Clone();
                }

                partnerInfoOverride.TargetMultiplicity = EdmMultiplicity.ZeroOrOne;
            }

            return(partnerInfoOverride ?? partnerInfo);
        }
예제 #5
0
        /// <summary>
        /// Creates a navigation property from the given information.
        /// </summary>
        /// <param name="declaringType">The type that declares this property.</param>
        /// <param name="propertyInfo">Information to create the navigation property.</param>
        /// <returns>Created navigation property.</returns>
        public static EdmNavigationProperty CreateNavigationProperty(IEdmStructuredType declaringType, EdmNavigationPropertyInfo propertyInfo)
        {
            EdmUtil.CheckArgumentNull(propertyInfo, "propertyInfo");
            EdmUtil.CheckArgumentNull(propertyInfo.Name, "propertyInfo.Name");
            EdmUtil.CheckArgumentNull(propertyInfo.Target, "propertyInfo.Target");

            return(new EdmNavigationProperty(
                       declaringType,
                       propertyInfo.Name,
                       CreateNavigationPropertyType(propertyInfo.Target, propertyInfo.TargetMultiplicity, "propertyInfo.TargetMultiplicity"),
                       propertyInfo.DependentProperties,
                       propertyInfo.PrincipalProperties,
                       propertyInfo.ContainsTarget,
                       propertyInfo.OnDelete));
        }