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


C# ODataMessageReader.ReadEntityReferenceLink方法代码示例

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


在下文中一共展示了ODataMessageReader.ReadEntityReferenceLink方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:larsenjo,项目名称:odata.net,代码行数:32,代码来源:UpdateHandler.cs

示例2: Read

        /// <inheritdoc />
        public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            IEdmNavigationProperty navigationProperty = GetNavigationProperty(readContext.Path);

            if (navigationProperty == null)
            {
                throw new SerializationException(SRResources.NavigationPropertyMissingDuringDeserialization);
            }

            ODataEntityReferenceLink entityReferenceLink = messageReader.ReadEntityReferenceLink(navigationProperty);

            if (entityReferenceLink != null)
            {
                return ResolveContentId(entityReferenceLink.Url, readContext);
            }

            return null;
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:29,代码来源:ODataEntityReferenceLinkDeserializer.cs

示例3: Read

        public override object Read(ODataMessageReader messageReader, ODataDeserializerReadContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            ODataEntityReferenceLink entityReferenceLink = messageReader.ReadEntityReferenceLink();
            if (entityReferenceLink != null)
            {
                return entityReferenceLink.Url;
            }

            return null;
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:15,代码来源:ODataEntityReferenceLinkDeserializer.cs

示例4: Read

        public override object Read(ODataMessageReader messageReader, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            // TODO: Feature #664 - Support JSON light (pass navigation property).
            ODataEntityReferenceLink entityReferenceLink = messageReader.ReadEntityReferenceLink();

            if (entityReferenceLink != null)
            {
                return entityReferenceLink.Url;
            }

            return null;
        }
开发者ID:jlamfers,项目名称:aspnetwebstack,代码行数:17,代码来源:ODataEntityReferenceLinkDeserializer.cs

示例5: Read

        /// <inheritdoc />
        public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            if (readContext == null)
            {
                throw Error.ArgumentNull("readContext");
            }

            ODataEntityReferenceLink entityReferenceLink = messageReader.ReadEntityReferenceLink();

            if (entityReferenceLink != null)
            {
                return ResolveContentId(entityReferenceLink.Url, readContext);
            }

            return null;
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:22,代码来源:ODataEntityReferenceLinkDeserializer.cs

示例6: TestReadEntityReferenceLink_InJsonLight_WithNavigationProperty_DoesNotThrow

        public void TestReadEntityReferenceLink_InJsonLight_WithNavigationProperty_DoesNotThrow()
        {
            // Arrange
            IODataRequestMessage request = CreateJsonLightRequest("{\"@odata.id\":\"aa:b\"}");
            ODataMessageReaderSettings settings = CreateSettings();
            IEdmModel model = CreateModel();

            using (ODataMessageReader reader = new ODataMessageReader(request, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => reader.ReadEntityReferenceLink());
            }
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:13,代码来源:ODataMessageReaderLearningTests.cs

示例7: TestReadEntityReferenceLink_InJsonLight_WithNavigationProperty_DoesNotThrow

        public void TestReadEntityReferenceLink_InJsonLight_WithNavigationProperty_DoesNotThrow()
        {
            // Arrange
            IODataRequestMessage request = CreateJsonLightRequest("{\"odata.id\":\"aa:b\"}");
            ODataMessageReaderSettings settings = CreateSettings();
            IEdmModel model = CreateModel();
            IEdmNavigationProperty navigationProperty =
                model.EntityContainers().Single().EntitySets().First().NavigationPropertyBindings.First().NavigationProperty;

            using (ODataMessageReader reader = new ODataMessageReader(request, settings, model))
            {
                // Act & Assert
                Assert.DoesNotThrow(() => reader.ReadEntityReferenceLink(navigationProperty));
            }
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:15,代码来源:ODataMessageReaderLearningTests.cs

示例8: 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

示例9: QueryReferenceLink

        public ODataEntityReferenceLink QueryReferenceLink(string uri, string mimeType)
        {
            ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings() { BaseUri = baseUri };

            var queryRequestMessage = new HttpWebRequestMessage(new Uri(baseUri.AbsoluteUri + uri, UriKind.Absolute));
            queryRequestMessage.SetHeader("Accept", mimeType);

            var queryResponseMessage = queryRequestMessage.GetResponse();
            Assert.AreEqual(200, queryResponseMessage.StatusCode);
            ODataEntityReferenceLink item = null;
            if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
            {
                using (var messageReader = new ODataMessageReader(queryResponseMessage, readerSettings, model))
                {
                    item = messageReader.ReadEntityReferenceLink();
                }
            }

            return item;
        }
开发者ID:cxlove,项目名称:odata.net,代码行数:20,代码来源:QueryOptionTestsHelper.cs

示例10: WriteAndVerifySingleLink

        private string WriteAndVerifySingleLink(StreamResponseMessage responseMessage, ODataMessageWriter messageWriter, string mimeType)
        {
            var link = new ODataEntityReferenceLink() { Url = new Uri(this.ServiceUri + "Order(-10)") };

            messageWriter.WriteEntityReferenceLink(link);
            var stream = responseMessage.GetStream();
            if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata))
            {
                stream.Seek(0, SeekOrigin.Begin);
                var settings = new ODataMessageReaderSettings() { BaseUri = this.ServiceUri };

                ODataMessageReader messageReader = new ODataMessageReader(responseMessage, settings, WritePayloadHelper.Model);

                ODataEntityReferenceLink linkRead = messageReader.ReadEntityReferenceLink();
                Assert.IsTrue(linkRead.Url.AbsoluteUri.Contains("Order(-10)"), "linkRead.Url");
            }

            return WritePayloadHelper.ReadStreamContent(stream);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:19,代码来源:WriteJsonWithoutModelTests.cs


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