internal static Uri GenerateFunctionLink(this ResourceSetContext feedContext, string bindingParameterType, string functionName, IEnumerable <string> parameterNames) { Contract.Assert(feedContext != null); if (feedContext.EntitySetBase is IEdmContainedEntitySet) { return(null); } if (feedContext.EdmModel == null) { return(null); } IEdmModel model = feedContext.EdmModel; string elementType = DeserializationHelpers.GetCollectionElementTypeName(bindingParameterType, isNested: false); Contract.Assert(elementType != null); IEdmTypeReference typeReference = model.FindDeclaredType(elementType).ToEdmTypeReference(true); IEdmTypeReference collection = new EdmCollectionTypeReference(new EdmCollectionType(typeReference)); IEdmOperation operation = model.FindDeclaredOperations(functionName).First(); return(feedContext.GenerateFunctionLink(collection, operation, parameterNames)); }
public void GetCollectionElementTypeName_ThrowsODataException_NestedCollection() { // Arrange & Act & Assert ExceptionAssert.Throws <ODataException>( () => DeserializationHelpers.GetCollectionElementTypeName("Collection(Edm.Int32)", true), "The type 'Collection(Edm.Int32)' is a nested collection type. Nested collection types are not allowed."); }
internal static Uri GenerateActionLink(this FeedContext feedContext, string bindingParameterType, string actionName) { Contract.Assert(feedContext != null); if (feedContext.EntitySetBase is IEdmContainedEntitySet) { return(null); } IList <ODataPathSegment> actionPathSegments = new List <ODataPathSegment>(); feedContext.GenerateBaseODataPathSegmentsForFeed(actionPathSegments); // generate link with cast if the navigation source doesn't match the type the action is bound to. if (feedContext.EntitySetBase.Type.FullTypeName() != bindingParameterType) { string elementType = DeserializationHelpers.GetCollectionElementTypeName(bindingParameterType, isNested: false); Contract.Assert(elementType != null); actionPathSegments.Add(new CastPathSegment(elementType)); } actionPathSegments.Add(new BoundActionPathSegment(actionName)); string actionLink = feedContext.Url.CreateODataLink(actionPathSegments); return(actionLink == null ? null : new Uri(actionLink)); }
internal static Uri GenerateFunctionLink(this FeedContext feedContext, string bindingParameterType, string functionName, IEnumerable <string> parameterNames) { Contract.Assert(feedContext != null); if (feedContext.EntitySetBase is IEdmContainedEntitySet) { return(null); } IList <ODataPathSegment> functionPathSegments = new List <ODataPathSegment>(); feedContext.GenerateBaseODataPathSegmentsForFeed(functionPathSegments); // generate link with cast if the navigation source type doesn't match the entity type the function is bound to. if (feedContext.EntitySetBase.Type.FullTypeName() != bindingParameterType) { string elementType = DeserializationHelpers.GetCollectionElementTypeName(bindingParameterType, isNested: false); Contract.Assert(elementType != null); functionPathSegments.Add(new CastPathSegment(elementType)); } Dictionary <string, string> parametersDictionary = new Dictionary <string, string>(); // skip the binding parameter foreach (string param in parameterNames.Skip(1)) { parametersDictionary.Add(param, "@" + param); } functionPathSegments.Add(new BoundFunctionPathSegment(functionName, parametersDictionary)); string functionLink = feedContext.Url.CreateODataLink(functionPathSegments); return(functionLink == null ? null : new Uri(functionLink)); }