Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make dynamic edm model support odata queries

I have been trying to adapt the DynamicEdmModelCreation sample from https://github.com/OData/ODataSamples/tree/master/WebApi/v4/DynamicEdmModelCreation into a workable v3 version (I want to load odata directly into excel, which doesn't support odata v4 yet)

I added config.AddODataQueryFilter() to the setup and [EnableQuery] on the Controller's get method, but I now receive the exception:

A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Web.Http.OData.dll

Additional information: 'EnumerableQuery`1' cannot be serialized using the ODataMediaTypeFormatter.

Which is being thrown from https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/OData/src/System.Web.Http.OData/OData/Formatter/ODataMediaTypeFormatter.cs#L577

Is the fact that my Controller's Get method is returning an EdmEntityObjectCollection an issue? I would have thought that just adding the EnableQuery attribute would be enough for the framework to know how to apply that query operation to the EdmEntityObjectCollection that I'm returning (which will have lots more data than potentially needed)

like image 827
BrandonAGr Avatar asked Mar 27 '15 18:03

BrandonAGr


People also ask

What is EDM model in OData?

OData service uses an abstract data model called Entity Data Model (EDM) to describe the exposed data in the service. OData client can issue a GET request to the root URL of the OData service with $metadata to get an XML representation of the service's data model.

What is OData type?

The odata. type annotation specifies the type of a JSON object or name/value pair. Its value is a URI that identifies the type of the property or object. For built-in primitive types the value is the unqualified name of the primitive type, specified as a URI fragment.


1 Answers

What you have done is right, but OData WebApi doesn't support query options in un-typed scenario now, and there is an open issue about this feature.

like image 65
Fan Ouyang Avatar answered Oct 08 '22 16:10

Fan Ouyang