Esempio n. 1
0
        /// <summary>
        /// Creates a new instance of ResourceReferentialConstraint.
        /// </summary>
        /// <param name="principalEnd">Principal end of the referential constraint.</param>
        /// <param name="dependentProperties">List of the properties from the dependent end that take part in this constraint.</param>
        internal ResourceReferentialConstraint(ResourceAssociationTypeEnd principalEnd, IEnumerable <ResourceProperty> dependentProperties)
        {
            Debug.Assert(principalEnd != null, "principalEnd != null");
            Debug.Assert(dependentProperties != null, "dependentProperties != null");
            Debug.Assert(principalEnd.ResourceType.KeyProperties.Count == dependentProperties.Count(), "principalEnd.ResourceType.KeyProperties.Count == dependentProperties.Count()");

            this.PrincipalEnd        = principalEnd;
            this.DependentProperties = dependentProperties;
        }
        /// <summary>
        /// Creates a new instance of ResourceReferentialConstraint.
        /// </summary>
        /// <param name="principalEnd">Principal end of the referential constraint.</param>
        /// <param name="dependentProperties">List of the properties from the dependent end that take part in this constraint.</param>
        internal ResourceReferentialConstraint(ResourceAssociationTypeEnd principalEnd, IEnumerable<ResourceProperty> dependentProperties)
        {
            Debug.Assert(principalEnd != null, "principalEnd != null");
            Debug.Assert(dependentProperties != null, "dependentProperties != null");
            Debug.Assert(principalEnd.ResourceType.KeyProperties.Count == dependentProperties.Count(), "principalEnd.ResourceType.KeyProperties.Count == dependentProperties.Count()");

            this.PrincipalEnd = principalEnd;
            this.DependentProperties = dependentProperties;
        }
        /// <summary>
        /// Creates a new instance of AssociationInfo to store information about an association.
        /// </summary>
        /// <param name="name">name of the association.</param>
        /// <param name="namespaceName">namespaceName of the association.</param>
        /// <param name="end1">first end of the association.</param>
        /// <param name="end2">second end of the association.</param>
        internal ResourceAssociationType(string name, string namespaceName, ResourceAssociationTypeEnd end1, ResourceAssociationTypeEnd end2)
        {
            Debug.Assert(!String.IsNullOrEmpty(name), "!String.IsNullOrEmpty(name)");
            Debug.Assert(end1 != null && end2 != null, "end1 != null && end2 != null");

            this.name          = name;
            this.namespaceName = namespaceName;
            this.fullName      = namespaceName + "." + name;
            this.end1          = end1;
            this.end2          = end2;
        }
        /// <summary>
        /// Creates a new instance of AssociationInfo to store information about an association.
        /// </summary>
        /// <param name="name">name of the association.</param>
        /// <param name="namespaceName">namespaceName of the association.</param>
        /// <param name="end1">first end of the association.</param>
        /// <param name="end2">second end of the association.</param>
        internal ResourceAssociationType(string name, string namespaceName, ResourceAssociationTypeEnd end1, ResourceAssociationTypeEnd end2)
        {
            Debug.Assert(!String.IsNullOrEmpty(name), "!String.IsNullOrEmpty(name)");
            Debug.Assert(end1 != null && end2 != null, "end1 != null && end2 != null");

            this.name = name;
            this.namespaceName = namespaceName;
            this.fullName = namespaceName + "." + name;
            this.end1 = end1;
            this.end2 = end2;
        }
        /// <summary>
        /// Retrieve the related end for the given resource set, type and property.
        /// </summary>
        /// <param name="resourceType">resource type for the source end</param>
        /// <param name="resourceProperty">resource property for the source end</param>
        /// <returns>Related association type end for the given parameters</returns>
        internal ResourceAssociationTypeEnd GetRelatedResourceAssociationSetEnd(ResourceType resourceType, ResourceProperty resourceProperty)
        {
            Debug.Assert(resourceType != null, "resourceType != null");

            ResourceAssociationTypeEnd thisEnd = this.GetResourceAssociationTypeEnd(resourceType, resourceProperty);

            if (thisEnd != null)
            {
                foreach (ResourceAssociationTypeEnd end in new[] { this.end1, this.end2 })
                {
                    if (end != thisEnd)
                    {
                        return(end);
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Populate the ResourceAssociationType from the AssociationType instance.
        /// </summary>
        /// <param name="associationType">AssociationType instance.</param>
        /// <param name="end1">ResourceAssociationTypeEnd instance.</param>
        /// <param name="end2">ResourceAssociationTypeEnd instance.</param>
        /// <returns>An instance of ResourceAssociationType.</returns>
        private static ResourceAssociationType PopulateResourceAssociationType(AssociationType associationType, ResourceAssociationTypeEnd end1, ResourceAssociationTypeEnd end2)
        {
            ResourceAssociationType resourceAssociationType = new ResourceAssociationType(
                            associationType.Name,
                            associationType.NamespaceName,
                            end1,
                            end2);

            ObjectContextServiceProvider.PopulateAnnotations(associationType.MetadataProperties, resourceAssociationType.AddCustomAnnotation);

            if (associationType.ReferentialConstraints != null && associationType.ReferentialConstraints.Count != 0)
            {
                PopulateReferentialConstraint(resourceAssociationType, associationType.ReferentialConstraints[0]);
            }

            return resourceAssociationType;
        }
 /// <summary>
 /// Populate the ResourceAssociationTypeEnd from the AssociationEndMember instance.
 /// </summary>
 /// <param name="end">Instance of AssociationEndMember.</param>
 /// <param name="resourceType">ResourceType instance which the end refers to.</param>
 /// <param name="resourceProperty">ResourceProperty instance.</param>
 /// <returns>An instance of ResourceAssociationTypeEnd.</returns>
 private static ResourceAssociationTypeEnd PopulateResourceAssociationTypeEnd(AssociationEndMember end, ResourceType resourceType, ResourceProperty resourceProperty)
 {
     ResourceAssociationTypeEnd resourceAssociationTypeEnd = new ResourceAssociationTypeEnd(end.Name, resourceType, resourceProperty, ObjectContextServiceProvider.GetMultiplicity(end.RelationshipMultiplicity), (EdmOnDeleteAction)end.DeleteBehavior);
     ObjectContextServiceProvider.PopulateAnnotations(end.MetadataProperties, resourceAssociationTypeEnd.AddCustomAnnotation);
     return resourceAssociationTypeEnd;
 }