Support external creation of IEdmModel


Currently for an IEdmModel to be used with the ODataMediaTypeFormatters, it MUST be built using an ODataModelBuilder. This is because the formatters require an annotation on IEdmEntitySet using a class called EntitySetLinkBuilderAnnotation, and this class is internal.

However there are clearly scenarios where people want to create there own IEdmModel. For example from:
  • DbContext
  • IDataServiceMetadataProvider
I see a layered solution.

First make EntitySetLinkBuilderAnnotation public, and give it a constructor that doesn't require an EntitySetConfiguration (you don't necessarily have one of those).
Second make the Formatter annotate the model if an EntitySetLinkBuilderAnnotation is not found, this way if a service follows conventions (most do) then you don't need to annotate the IEdmModel you build at all.

The first part has already been completed with this commit

file attachments

Closed Jul 19, 2013 at 4:13 PM by jacalvar


DarinShapiro1 wrote Jan 29, 2013 at 4:47 PM

I'm currently working with a database that unfortunately didn't follow any standard naming conventions as well as missing a lot of foreign keys, etc. I've cleaned up my model quite a bit, so I have EntitySetConfiguration's that were created with customized T4 templates. Would this change you're proposing allow me to use these if needed?

raghuramn wrote Jul 17, 2013 at 10:52 PM


You can now use externally created EDM models with MapODataRoute. A sample on how to get an IEdmModel from Entityframework DBContext is here.

masaeedu wrote Jun 15 at 5:12 PM

  1. Does this work for OData v4? The namespaces have changed, and now there is a new OData.Edm.IEdmModel that I can't see any way to generate directly from a DbContext. Serializing the EDM model from Entity Framework, then reserializing using the TryParse method on EdmxReader doesn't seem to work (you get a serialization exception).