Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dozer75/4cf219e041681de687087eb2d66b8743 to your computer and use it in GitHub Desktop.
Save dozer75/4cf219e041681de687087eb2d66b8743 to your computer and use it in GitHub Desktop.
// Use nuget to reference Microsoft.OData.Core 7.4.4
using System;
using System.IO;
using System.Text;
using Microsoft.OData;
using Microsoft.OData.Edm;
namespace ThrowIfTypeConflictsWithMetadataIgnored
{
internal class Program
{
private static void Main()
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("{ \"@odata.context\": \"http://host/$metadata#People/$entity\", \"Id\": 1, \"Name\": null }")))
{
var inMemoryMessage = new InMemoryMessage
{
Stream = stream
};
var model = new EdmModel();
var type = new EdmEntityType("NS", "Person");
type.AddKeys(type.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
type.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String, false);
model.AddElement(type);
var container = new EdmEntityContainer("NS", "Container");
var set = container.AddEntitySet("People", type);
model.AddElement(container);
using (var messageReader = new ODataMessageReader((IODataResponseMessage) inMemoryMessage,
new ODataMessageReaderSettings
{
BaseUri = new Uri("http://host"),
Validations = ValidationKinds.ThrowOnDuplicatePropertyNames
},
model))
{
var reader = messageReader.CreateODataResourceReader(set, type);
// Throws exception
reader.Read();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment