Skip to content

Instantly share code, notes, and snippets.

@kiewic
Created September 17, 2016 00:04
Show Gist options
  • Save kiewic/ca487b27606344f2dd148b99f74e29a2 to your computer and use it in GitHub Desktop.
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.
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);
}
}
}
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