Пример #1
0
        /// <summary>
        /// Create contextUrlInfo for delta
        /// </summary>
        /// <param name="typeContext">The ODataResourceTypeContext to be used.</param>
        /// <param name="version">The OData version of the response.</param>
        /// <param name="kind">The delta kind.</param>
        /// <param name="odataUri">The odata uri info for current query.</param>
        /// <returns>The generated ODataContextUrlInfo.</returns>
        internal static ODataContextUrlInfo Create(ODataResourceTypeContext typeContext, ODataVersion version, ODataDeltaKind kind, ODataUri odataUri = null)
        {
            Debug.Assert(typeContext != null, "typeContext != null");

            ODataContextUrlInfo contextUriInfo = new ODataContextUrlInfo()
            {
                IsUnknownEntitySet          = typeContext.NavigationSourceKind == EdmNavigationSourceKind.UnknownEntitySet,
                NavigationSource            = typeContext.NavigationSourceName,
                TypeCast                    = typeContext.NavigationSourceEntityTypeName == typeContext.ExpectedResourceTypeName ? null : typeContext.ExpectedResourceTypeName,
                TypeName                    = typeContext.NavigationSourceEntityTypeName,
                IncludeFragmentItemSelector = kind == ODataDeltaKind.Resource && typeContext.NavigationSourceKind != EdmNavigationSourceKind.Singleton,
                DeltaKind                   = kind,
                NavigationPath              = ComputeNavigationPath(typeContext.NavigationSourceKind, null, typeContext.NavigationSourceName),
            };

            // Only use odata uri in with model case.
            if (typeContext is ODataResourceTypeContext.ODataResourceTypeContextWithModel)
            {
                contextUriInfo.NavigationPath = ComputeNavigationPath(typeContext.NavigationSourceKind, odataUri,
                                                                      typeContext.NavigationSourceName);
                contextUriInfo.ResourcePath = ComputeResourcePath(odataUri);
                contextUriInfo.QueryClause  = ComputeQueryClause(odataUri, version);
                contextUriInfo.IsUndeclared = ComputeIfIsUndeclared(odataUri);
            }

            return(contextUriInfo);
        }
Пример #2
0
        /// <summary>
        /// Create ODataContextUrlInfo from ODataResourceTypeContext
        /// </summary>
        /// <param name="typeContext">The ODataResourceTypeContext to be used.</param>
        /// <param name="version">The OData Version of the response</param>
        /// <param name="isSingle">Whether target is single item.</param>
        /// <param name="odataUri">The odata uri info for current query.</param>
        /// <returns>The generated ODataContextUrlInfo.</returns>
        internal static ODataContextUrlInfo Create(ODataResourceTypeContext typeContext, ODataVersion version, bool isSingle, ODataUri odataUri = null)
        {
            Debug.Assert(typeContext != null, "typeContext != null");

            var hasNavigationSourceInfo = typeContext.NavigationSourceKind != EdmNavigationSourceKind.None ||
                                          !string.IsNullOrEmpty(typeContext.NavigationSourceName);

            var typeName = hasNavigationSourceInfo
                           ? typeContext.NavigationSourceFullTypeName
                           : typeContext.ExpectedResourceTypeName == null
                             ? null
                             : isSingle
                               ? typeContext.ExpectedResourceTypeName
                               : EdmLibraryExtensions.GetCollectionTypeName(typeContext.ExpectedResourceTypeName);

            return(new ODataContextUrlInfo()
            {
                HasNavigationSourceInfo = hasNavigationSourceInfo,
                IsUnknownEntitySet = typeContext.NavigationSourceKind == EdmNavigationSourceKind.UnknownEntitySet,
                NavigationSource = typeContext.NavigationSourceName,
                TypeCast = typeContext.NavigationSourceEntityTypeName == null ||
                           typeContext.ExpectedResourceTypeName == null ||
                           typeContext.ExpectedResourceType is IEdmComplexType ||
                           typeContext.NavigationSourceEntityTypeName == typeContext.ExpectedResourceTypeName
                           ? null : typeContext.ExpectedResourceTypeName,
                TypeName = typeName,
                IncludeFragmentItemSelector = isSingle && typeContext.NavigationSourceKind != EdmNavigationSourceKind.Singleton,
                NavigationPath = ComputeNavigationPath(typeContext.NavigationSourceKind, odataUri, typeContext.NavigationSourceName),
                ResourcePath = ComputeResourcePath(odataUri),
                QueryClause = ComputeQueryClause(odataUri, version),
                IsUndeclared = ComputeIfIsUndeclared(odataUri)
            });
        }