Created
September 17, 2016 00:04
-
-
Save kiewic/ca487b27606344f2dd148b99f74e29a2 to your computer and use it in GitHub Desktop.
OData: Generate the EDMX $metadata document from an IEdmModel and print it to the console.
This file contains hidden or 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
using Microsoft.OData.Core; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Web.OData.Builder; | |
namespace FooApp | |
{ | |
class FakeODataResponseMessage : IODataResponseMessage | |
{ | |
public IEnumerable<KeyValuePair<string, string>> Headers | |
{ | |
get | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
public int StatusCode | |
{ | |
get | |
{ | |
throw new NotImplementedException(); | |
} | |
set | |
{ | |
Console.WriteLine(value); | |
} | |
} | |
public string GetHeader(string headerName) | |
{ | |
return null; | |
} | |
public Stream GetStream() | |
{ | |
return Console.OpenStandardOutput(); | |
} | |
public void SetHeader(string headerName, string headerValue) | |
{ | |
Console.WriteLine(headerName + ": " + headerValue); | |
} | |
} | |
} |
This file contains hidden or 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
using Microsoft.OData.Core; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Web.OData.Builder; | |
namespace FooApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var builder = new ODataConventionModelBuilder(); | |
// TODO: Define OData model | |
var edmModel = builder.GetEdmModel(); | |
var writerSettings = new ODataMessageWriterSettings() | |
{ | |
Indent = true, | |
}; | |
using (var msgWriter = new ODataMessageWriter( | |
new FakeODataResponseMessage(), | |
writerSettings, | |
edmModel)) | |
{ | |
msgWriter.WriteMetadataDocument(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment