本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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));
}
}
示例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);
}
示例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;
}
示例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);
}