If user wants to write his own metadata controller to return metadata which is different with the model in the formatter, it will still return the model from formatter.
For example, I build an empty edm model from CustomMetadataController.
public class CustomMetadataController : ApiController
{
public IEdmModel GetMetadata()
{
ODataConventionModelBuilder mb = new ODataConventionModelBuilder();
return mb.GetEdmModel();
//return Program.GetEdmModel();
}
}
In my formatter, I use another model:
public static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder mb = new ODataConventionModelBuilder();
mb.EntitySet<Todo>("Todo").EntityType.Property(t => t.Name).IsRequired();
return mb.GetEdmModel();
}
And configure route as:
configuration.Routes.MapHttpRoute(ODataRouteNames.Metadata, "$metadata", new { Controller = "CustomMetadata", Action = "GetMetadata" });
The returned metadata is still has Todo entity set. This is quite weird.
Comments: You need to return a HttpResponseMessage and pass the formatter with the customized model and pass that formatter to the request.CreateResponse overload.
For example, I build an empty edm model from CustomMetadataController.
public class CustomMetadataController : ApiController
{
public IEdmModel GetMetadata()
{
ODataConventionModelBuilder mb = new ODataConventionModelBuilder();
return mb.GetEdmModel();
//return Program.GetEdmModel();
}
}
In my formatter, I use another model:
public static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder mb = new ODataConventionModelBuilder();
mb.EntitySet<Todo>("Todo").EntityType.Property(t => t.Name).IsRequired();
return mb.GetEdmModel();
}
And configure route as:
configuration.Routes.MapHttpRoute(ODataRouteNames.Metadata, "$metadata", new { Controller = "CustomMetadata", Action = "GetMetadata" });
The returned metadata is still has Todo entity set. This is quite weird.
Comments: You need to return a HttpResponseMessage and pass the formatter with the customized model and pass that formatter to the request.CreateResponse overload.