当前位置: 首页>>代码示例>>C#>>正文


C# QueryContext.ResolveQuery方法代码示例

本文整理汇总了C#中QueryContext.ResolveQuery方法的典型用法代码示例。如果您正苦于以下问题:C# QueryContext.ResolveQuery方法的具体用法?C# QueryContext.ResolveQuery怎么用?C# QueryContext.ResolveQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QueryContext的用法示例。


在下文中一共展示了QueryContext.ResolveQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessUpdateEntityReference

        private void ProcessUpdateEntityReference(IODataRequestMessage requestMessage, IODataResponseMessage responseMessage, ODataPath odataPath)
        {
            // This is for change the reference in single-valued navigation property
            // PUT ~/Person(0)/Parent/$ref
            // {
            //     "@odata.context": "http://host/service/$metadata#$ref",
            //     "@odata.id": "Orders(10643)"
            // }

            if (this.HttpMethod == HttpMethod.PATCH)
            {
                throw Utility.BuildException(HttpStatusCode.MethodNotAllowed, "PATCH on a reference link is not supported.", null);
            }

            // Get the parent first
            var level = this.QueryContext.QueryPath.Count - 2;
            var parent = this.QueryContext.ResolveQuery(this.DataSource, level);

            var navigationPropertyName = ((NavigationPropertyLinkSegment)odataPath.LastSegment).NavigationProperty.Name;

            using (var messageReader = new ODataMessageReader(requestMessage, this.GetReaderSettings(), this.DataSource.Model))
            {
                var referenceLink = messageReader.ReadEntityReferenceLink();
                var queryContext = new QueryContext(this.ServiceRootUri, referenceLink.Url, this.DataSource.Model);
                var target = queryContext.ResolveQuery(this.DataSource);

                this.DataSource.UpdateProvider.UpdateLink(parent, navigationPropertyName, target);
                this.DataSource.UpdateProvider.SaveChanges();
            }

            ResponseWriter.WriteEmptyResponse(responseMessage);
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:32,代码来源:UpdateHandler.cs

示例2: ProcessUpsertEntity

        private void ProcessUpsertEntity(IODataRequestMessage requestMessage, IODataResponseMessage responseMessage, ODataPath odataPath)
        {
            if (this.QueryContext.Target.TypeKind == EdmTypeKind.Entity && !this.QueryContext.Target.IsReference)
            {
                Uri parentUri = this.QueryContext.Target.BuildContainerUri(this.ServiceRootUri);
                QueryContext parentContext = new QueryContext(this.ServiceRootUri, parentUri, this.DataSource.Model);

                if (parentContext.Target.IsEntitySet)
                {
                    // Update a entity under a entity set => Upsert

                    // TODO: Do we need to preserver the key value?
                    new CreateHandler(this, parentContext.QueryUri).Process(requestMessage, responseMessage);
                }
                else
                {
                    // Update Singleton or single value entity from null value.
                    var parent = parentContext.ResolveQuery(this.DataSource);

                    // TODO: It might not correct here, since the last segment could be type segment.
                    NavigationPropertySegment navSegment = (NavigationPropertySegment)odataPath.LastSegment;
                    var targetObject = Utility.CreateResource(this.QueryContext.Target.Type);
                    parent.GetType().GetProperty(navSegment.NavigationProperty.Name).SetValue(parent, targetObject, null);

                    ProcessUpdateRequestBody(requestMessage, responseMessage, targetObject, true);
                }
            }
            else
            {
                throw Utility.BuildException(HttpStatusCode.NotFound);
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:32,代码来源:UpdateHandler.cs

示例3: ProcessCreateLink

        private void ProcessCreateLink(IODataRequestMessage requestMessage, IODataResponseMessage responseMessage)
        {
            var level = this.QueryContext.QueryPath.Count - 2;
            var parent = this.QueryContext.ResolveQuery(this.DataSource, level);

            var odataPath = this.QueryContext.QueryPath;
            var collectionPropertyName = ((NavigationPropertyLinkSegment)odataPath.LastSegment).NavigationProperty.Name;

            using (var messageReader = new ODataMessageReader(requestMessage, this.GetReaderSettings(), this.DataSource.Model))
            {
                var referenceLink = messageReader.ReadEntityReferenceLink();
                var queryContext = new QueryContext(this.ServiceRootUri, referenceLink.Url, this.DataSource.Model);
                var target = queryContext.ResolveQuery(this.DataSource);

                this.DataSource.UpdateProvider.CreateLink(parent, collectionPropertyName, target);
                this.DataSource.UpdateProvider.SaveChanges();
            }

            // Protocol 11.4.6.1 Add a Reference to a Collection-Valued Navigation Property
            // On successful completion, the response MUST be 204 No Content and contain an empty body.
            ResponseWriter.WriteEmptyResponse(responseMessage);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:22,代码来源:CreateHandler.cs

示例4: GenerateDeltaItemsFromDeletedEntities

        /// <summary>
        /// Generate deleted entry and deleted link items
        /// </summary>
        /// <param name="parentId">Parent Id</param>
        /// <param name="relationShip">Navigation property name</param>
        private void GenerateDeltaItemsFromDeletedEntities(string parentId, string relationShip)
        {
            foreach (DeltaSnapshotEntry entry in this.DeltaSnapshot.Entries)
            {
                // Get all top level entities which do not contained in new results
                if (entry.ParentId == parentId && entry.RelationShip == relationShip)
                {
                    // Verify if the entry is deleted now, since some of them may dispare because $filter
                    var verifyresult = new QueryContext(this.ServiceRootUri, new Uri(entry.Id), this.DataSource.Model);
                    object queryResults = verifyresult.ResolveQuery(this.DataSource);

                    if (queryResults == null)
                    {
                        var deletedEntry = new ODataDeltaDeletedEntry(entry.Id, DeltaDeletedEntryReason.Deleted);
                        deletedEntry.SetSerializationInfo(new ODataDeltaSerializationInfo
                        {
                            NavigationSourceName = (verifyresult.QueryPath.LastSegment as KeySegment).NavigationSource.Name,
                        });
                        this.DeltaItems.Add(deletedEntry);
                        if (!string.IsNullOrEmpty(parentId))
                        {
                            var deltaDeletedLink = new ODataDeltaDeletedLink(new Uri(parentId), new Uri(entry.Id), relationShip);
                            deltaDeletedLink.SetSerializationInfo(new ODataDeltaSerializationInfo
                            {
                                NavigationSourceName = (verifyresult.QueryPath.LastSegment as KeySegment).NavigationSource.Name,
                            });
                            this.DeltaItems.Add(deltaDeletedLink);
                        }
                    }
                    else
                    {
                        var deletedEntry = new ODataDeltaDeletedEntry(entry.Id, DeltaDeletedEntryReason.Changed);
                        deletedEntry.SetSerializationInfo(new ODataDeltaSerializationInfo
                        {
                            NavigationSourceName = (verifyresult.QueryPath.LastSegment as KeySegment).NavigationSource.Name,
                        });
                        this.DeltaItems.Add(deletedEntry);
                    }
                }
            }
        }
开发者ID:nickgoodrow,项目名称:ODataSamples,代码行数:46,代码来源:DeltaHandler.cs

示例5: ProcessDeleteLink

        private void ProcessDeleteLink(IODataResponseMessage responseMessage)
        {
            var segment = (NavigationPropertyLinkSegment)this.QueryContext.QueryPath.LastSegment;
            var propertyName = segment.NavigationProperty.Name;
            var parent = default(object);
            var target = default(object);

            if (this.QueryContext.QueryEntityIdSegment == null)
            {
                // single-valued navigation property
                parent = this.QueryContext.ResolveQuery(this.DataSource, this.QueryContext.QueryPath.Count - 2);
            }
            else
            {
                // collection-valued navigation property
                var queryUri = this.QueryContext.QueryUri;
                var parentUri = queryUri.AbsoluteUri.Substring(0, queryUri.AbsoluteUri.Length - queryUri.Query.Length);
                var parentContext = new QueryContext(this.ServiceRootUri, new Uri(parentUri, UriKind.Absolute), this.DataSource.Model);
                parent = parentContext.ResolveQuery(this.DataSource, parentContext.QueryPath.Count - 2);
                target = this.QueryContext.ResolveQuery(this.DataSource);
            }

            this.DataSource.UpdateProvider.DeleteLink(parent, propertyName, target);
            this.DataSource.UpdateProvider.SaveChanges();

            ResponseWriter.WriteEmptyResponse(responseMessage);
        }
开发者ID:chinadragon0515,项目名称:ODataSamples,代码行数:27,代码来源:DeleteHandler.cs


注:本文中的QueryContext.ResolveQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。