Created
May 2, 2018 11:55
-
-
Save dozer75/4cf219e041681de687087eb2d66b8743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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