Disable instance annotations
OData 6.12 .Net client is able to disable instance annotation materialization by turning on the flag DisableInstanceAnnotationMaterialization
in DataServiceContext
.
Let's have an example to demonstrate:
The response payload for the example is:
{
"@odata.context":"https://localhost/$metadata#People/$entity",
"PersonID":1,
"FirstName":"Bob",
"LastName":"Cat",
"HomeAddress":{
"@odata.type":"#Microsoft.Test.OData.Services.ODataWCFService.HomeAddress",
"@Microsoft.Test.OData.Services.ODataWCFService.AddressType":"Home",
"Street":"1 Microsoft Way",
"City":"Tokyo",
"PostalCode":"98052"
}
}
Here we compare the effects by turning off and on the DisableInstanceAnnotationMaterialization
flag.
Context.SendingRequest2 += (sender, eventArgs) => ((HttpWebRequestMessage)eventArgs.RequestMessage).SetHeader("Prefer", "odata.include-annotations=*");
// By default, DisableInstanceAnnotationMaterialization = false
var people = Context.People.ByKey(1).GetValue();
Context.TryGetAnnotation<string>(people.HomeAddress, "Microsoft.Test.OData.Services.ODataWCFService.AddressType", out annotation);
Assert.AreEqual("Home", annotation);
// Here we set DisableInstanceAnnotationMaterialization to true
Context.DisableInstanceAnnotationMaterialization = true;
people = Context.People.ByKey(1).GetValue();
Context.TryGetAnnotation<string>(people.HomeAddress, "Microsoft.Test.OData.Services.ODataWCFService.AddressType", out annotation);
Assert.AreEqual(null, annotation); // We are not able to get any annotation out.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for