internal static DataServiceProtocolVersion CalculateUriResponseMinProtocolVersion(ODataUri requestUri, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion) { DataServiceProtocolVersion expectedVersion = DataServiceProtocolVersion.V4; if (requestUri.IncludesInlineCountAllPages()) { expectedVersion = expectedVersion.IncreaseVersionIfRequired(DataServiceProtocolVersion.V4); } if (requestUri.IsCount()) { expectedVersion = expectedVersion.IncreaseVersionIfRequired(DataServiceProtocolVersion.V4); } else if (requestUri.IsProperty()) { var propertySegment = requestUri.LastSegment as PropertySegment; expectedVersion = expectedVersion.IncreaseVersionIfRequired(propertySegment.Property.CalculateProtocolVersion()); } else if (!requestUri.IsNamedStream()) { // Check service operations returning non-entity types if (requestUri.IsServiceOperation()) { var serviceOpSegment = requestUri.Segments.OfType <FunctionSegment>().Single(); DataType returnType = serviceOpSegment.Function.ReturnType; // Service ops returning complex values or bags of complex values, where the complex type has bag properties, are v3 var collectionType = returnType as CollectionDataType; if (collectionType != null) { // for service operations, the fact that a collection is returned does not mean it is a multivalue // so we unwrap the element type before calculating the version returnType = collectionType.ElementDataType; } expectedVersion = expectedVersion.IncreaseVersionIfRequired(returnType.CalculateDataTypeVersion()); } // Check entity types List <DataServiceProtocolVersion> dataServiceProtocolVersions = new List <DataServiceProtocolVersion>(); dataServiceProtocolVersions.Add(expectedVersion); if (!(requestUri.IsEntityReferenceLink() || requestUri.IsPropertyValue())) { foreach (EntitySet entitySet in requestUri.GetAllEntitySetsIncludingExpands()) { DataServiceProtocolVersion entitySetVersion = entitySet.CalculateEntitySetProtocolVersion(contentType, VersionCalculationType.Response, maxProtocolVersion, maxDataServiceVersion); dataServiceProtocolVersions.Add(entitySetVersion); if (entitySetVersion > maxDataServiceVersion) { return(VersionHelper.GetMaximumVersion(dataServiceProtocolVersions.ToArray())); } } } } return(expectedVersion); }