/// <summary> /// Goes through all visible types in the provider and determine the metadata version. /// </summary> /// <param name="provider">Provider wrapper instance.</param> /// <param name="metadataVersion">Returns the metadata version.</param> /// <param name="edmSchemaVersion">Returns the edm schema version.</param> internal static void UpdateMetadataVersion(DataServiceProviderWrapper provider, out Version metadataVersion, out MetadataEdmSchemaVersion edmSchemaVersion) { Debug.Assert(provider != null, "provider != null"); metadataVersion = Version4Dot0; edmSchemaVersion = MetadataEdmSchemaVersion.Version4Dot0; // Metadata versioning should only be impacted by visible types. A resource type is visible only when it is reachable from // a resource set with EntitySetRights != 'None' or a service op with ServiceOperationRights != None or it is a complex type // made visible through DataServiceConfiguration.EnableAccess(). foreach (ResourceType resourceType in provider.GetVisibleTypes()) { UpdateMetadataVersionForResourceType(resourceType, ref metadataVersion, ref edmSchemaVersion); } #if DEBUG // If there are multiple versions in future, add code here to do version-specific things foreach (OperationWrapper so in provider.GetVisibleOperations()) { Debug.Assert( so.ResultKind == ServiceOperationResultKind.DirectValue || so.ResultKind == ServiceOperationResultKind.Enumeration || so.ResultKind == ServiceOperationResultKind.QueryWithMultipleResults || so.ResultKind == ServiceOperationResultKind.QueryWithSingleResult || so.ResultKind == ServiceOperationResultKind.Void, "Otherwise we have introduced a new value for ServiceOperationResultKind, we might need to update the 'if' statement below."); } #endif }
internal static void UpdateMetadataVersion(DataServiceProviderWrapper provider, DataServiceOperationContext operationContext, out Version metadataVersion, out MetadataEdmSchemaVersion edmSchemaVersion) { metadataVersion = Version1Dot0; edmSchemaVersion = MetadataEdmSchemaVersion.Version1Dot0; if (!provider.IsV1Provider) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version1Dot1); } foreach (ResourceType type in provider.GetVisibleTypes(operationContext)) { UpdateMetadataVersionForResourceType(type, ref metadataVersion, ref edmSchemaVersion); } if (provider.HasAnnotations(operationContext)) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version3Dot0); } foreach (OperationWrapper wrapper in provider.GetVisibleOperations(operationContext)) { if (wrapper.Kind == OperationKind.Action) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version3Dot0); metadataVersion = WebUtil.RaiseVersion(metadataVersion, Version3Dot0); break; } if (((wrapper.ResultKind == ServiceOperationResultKind.Void) || (wrapper.ResultKind == ServiceOperationResultKind.QueryWithSingleResult)) || (((wrapper.ResultKind == ServiceOperationResultKind.DirectValue) || (wrapper.ResultType.ResourceTypeKind == ResourceTypeKind.ComplexType)) || (wrapper.ResultType.ResourceTypeKind == ResourceTypeKind.Primitive))) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version1Dot1); break; } } }