예제 #1
0
 public ResourceAssociationSetEnd(System.Data.Services.Providers.ResourceSet resourceSet, System.Data.Services.Providers.ResourceType resourceType, System.Data.Services.Providers.ResourceProperty resourceProperty)
 {
     WebUtil.CheckArgumentNull <System.Data.Services.Providers.ResourceSet>(resourceSet, "resourceSet");
     WebUtil.CheckArgumentNull <System.Data.Services.Providers.ResourceType>(resourceType, "resourceType");
     if ((resourceProperty != null) && ((resourceType.TryResolvePropertyName(resourceProperty.Name) == null) || (resourceProperty.TypeKind != ResourceTypeKind.EntityType)))
     {
         throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourcePropertyMustBeNavigationPropertyOnResourceType);
     }
     if (!resourceSet.ResourceType.IsAssignableFrom(resourceType) && !resourceType.IsAssignableFrom(resourceSet.ResourceType))
     {
         throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeAssignableToResourceSet);
     }
     if ((resourceProperty != null) && (DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty, null) != resourceType))
     {
         throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeTheDeclaringType(resourceType.FullName, resourceProperty.Name));
     }
     this.resourceSet      = resourceSet;
     this.resourceType     = resourceType;
     this.resourceProperty = resourceProperty;
 }
예제 #2
0
        public override ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            ResourceSet  set;
            ResourceType type;
            string       str;

            WebUtil.CheckArgumentNull <ResourceSet>(resourceSet, "resourceSet");
            WebUtil.CheckArgumentNull <ResourceType>(resourceType, "resourceType");
            WebUtil.CheckArgumentNull <ResourceProperty>(resourceProperty, "resourceProperty");
            if (!base.TryResolveResourceSet(resourceSet.Name, out set) || (set != resourceSet))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnknownResourceSet(resourceSet.Name));
            }
            if (!base.TryResolveResourceType(resourceType.FullName, out type) || (type != resourceType))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnknownResourceType(resourceType.FullName));
            }
            if (resourceType != DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty, null))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_ResourceTypeMustBeDeclaringTypeForProperty(resourceType.FullName, resourceProperty.Name));
            }
            ResourceType type2 = resourceProperty.ResourceType;

            if (type2.ResourceTypeKind != ResourceTypeKind.EntityType)
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_PropertyMustBeNavigationPropertyOnType(resourceProperty.Name, resourceType.FullName));
            }
            ResourceSet containerForResourceType = InternalGetContainerForResourceType(type2.InstanceType, base.EntitySets.Values);

            if (base.Types.Count <ResourceType>(rt => (rt.Name == resourceType.Name)) > 1)
            {
                str = resourceType.FullName.Replace('.', '_') + '_' + resourceProperty.Name;
            }
            else
            {
                str = resourceType.Name + '_' + resourceProperty.Name;
            }
            ResourceAssociationSetEnd end = new ResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty);

            return(new ResourceAssociationSet(str, end, new ResourceAssociationSetEnd(containerForResourceType, type2, null)));
        }