Exemplo n.º 1
0
        internal ResourceSetWrapper GetContainer(ResourceSetWrapper sourceContainer, ResourceType sourceResourceType, ResourceProperty navigationProperty)
        {
            ResourceAssociationSet set = this.GetResourceAssociationSet(sourceContainer, sourceResourceType, navigationProperty);

            if (set != null)
            {
                ResourceAssociationSetEnd end = set.GetRelatedResourceAssociationSetEnd(sourceContainer, sourceResourceType, navigationProperty);
                return(this.ValidateResourceSet(end.ResourceSet));
            }
            return(null);
        }
Exemplo n.º 2
0
        private void PairUpNavigationProperty(MetadataProviderEdmEntityContainer entityContainer, ResourceSetWrapper resourceSet, ResourceType resourceType, ResourceProperty navigationProperty)
        {
            string key = string.Concat(new object[] { resourceSet.Name, '_', resourceType.FullName, '_', navigationProperty.Name });

            if (!this.associationSetByKeyCache.ContainsKey(key))
            {
                ResourceAssociationSet resourceAssociationSet = this.MetadataProvider.GetResourceAssociationSet(resourceSet, resourceType, navigationProperty);
                if (resourceAssociationSet != null)
                {
                    string str2;
                    string str3;
                    ResourceAssociationSetEnd end = resourceAssociationSet.GetRelatedResourceAssociationSetEnd(resourceSet, resourceType, navigationProperty);
                    if (end.ResourceProperty != null)
                    {
                        ResourceAssociationSet set2 = this.MetadataProvider.GetResourceAssociationSet(this.MetadataProvider.ValidateResourceSet(end.ResourceSet), end.ResourceType, end.ResourceProperty);
                        if ((set2 == null) || (resourceAssociationSet.Name != set2.Name))
                        {
                            throw new InvalidOperationException(System.Data.Services.Strings.ResourceAssociationSet_BidirectionalAssociationMustReturnSameResourceAssociationSetFromBothEnd);
                        }
                    }
                    if (end.ResourceProperty != null)
                    {
                        str2 = string.Concat(new object[] { end.ResourceSet.Name, '_', end.ResourceType.FullName, '_', end.ResourceProperty.Name });
                    }
                    else
                    {
                        str2 = string.Concat(new object[] { end.ResourceSet.Name, "_Null_", resourceType.FullName, '_', navigationProperty.Name });
                    }
                    if (this.associationSetByKeyCache.TryGetValue(str2, out str3))
                    {
                        throw new InvalidOperationException(System.Data.Services.Strings.ResourceAssociationSet_MultipleAssociationSetsForTheSameAssociationTypeMustNotReferToSameEndSets(str3, resourceAssociationSet.Name, end.ResourceSet.Name));
                    }
                    ResourceAssociationType resourceAssociationType = resourceAssociationSet.ResourceAssociationType;
                    this.PairUpNavigationPropertyWithResourceAssociationSet(entityContainer, resourceAssociationSet, resourceAssociationType, resourceType, navigationProperty);
                    this.associationSetByKeyCache.Add(str2, resourceAssociationSet.Name);
                    this.associationSetByKeyCache.Add(key, resourceAssociationSet.Name);
                }
            }
        }
Exemplo n.º 3
0
            /// <summary>
            /// Get the resource association type from the given resource association set and one of its ends
            /// </summary>
            /// <param name="associationSet">Association set to get the association type</param>
            /// <param name="resourceSet">Resource set for one of the ends</param>
            /// <param name="resourceType">Resource type for one of the ends</param>
            /// <param name="navigationProperty">Resource property for one of the ends</param>
            /// <returns>Resource association type instance</returns>
            private ResourceAssociationType GetResourceAssociationType(ResourceAssociationSet associationSet, ResourceSetWrapper resourceSet, ResourceType resourceType, ResourceProperty navigationProperty)
            {
                string typeNamespace = this.GetTypeNamepace(resourceType);
                Dictionary<string, ResourceAssociationType> associationTypesInNamespece = this.GetAssociationTypesForNamespace(typeNamespace);

                ResourceAssociationType associationType;
                string associationTypeName = GetAssociationTypeName(associationSet);
                string associationTypeLookupKey = GetAssociationTypeLookupName(resourceType, navigationProperty);
                if (!associationTypesInNamespece.TryGetValue(associationTypeLookupKey, out associationType))
                {
                    string end1Name;
                    string end2Name;

                    bool isBiDirectional = associationSet.End1.ResourceProperty != null && associationSet.End2.ResourceProperty != null;
                    if (!isBiDirectional)
                    {
                        // If this association is not bi-directional, we use the type name as the from role name and the property name as the to role name
                        // This is the behavior for V1.
                        if (associationSet.End1.ResourceProperty != null)
                        {
                            end1Name = resourceType.Name;
                            end2Name = navigationProperty.Name;
                        }
                        else
                        {
                            end1Name = navigationProperty.Name;
                            end2Name = resourceType.Name;
                        }
                    }
                    else
                    {
                        // If the association is bi-directional, we use typeName_propertyName from each end as the name for that role
                        end1Name = GetAssociationTypeLookupName(associationSet.End1.ResourceType, associationSet.End1.ResourceProperty);
                        end2Name = GetAssociationTypeLookupName(associationSet.End2.ResourceType, associationSet.End2.ResourceProperty);
                        Debug.Assert(end1Name != end2Name, "end1Name != end2Name");
                    }

                    associationType = new ResourceAssociationType(
                        associationTypeName,
                        resourceType.Namespace,
                        new ResourceAssociationTypeEnd(end1Name, associationSet.End1.ResourceType, associationSet.End1.ResourceProperty, associationSet.End2.ResourceProperty),
                        new ResourceAssociationTypeEnd(end2Name, associationSet.End2.ResourceType, associationSet.End2.ResourceProperty, associationSet.End1.ResourceProperty));

                    associationTypesInNamespece.Add(associationTypeLookupKey, associationType);
                    if (isBiDirectional)
                    {
                        ResourceAssociationSetEnd relatedEnd = associationSet.GetRelatedResourceAssociationSetEnd(resourceSet, resourceType, navigationProperty);
                        string relatedEndLookupKey = GetAssociationTypeLookupName(relatedEnd.ResourceType, relatedEnd.ResourceProperty);
                        associationTypesInNamespece.Add(relatedEndLookupKey, associationType);
                    }
                }

                return associationType;
            }