0

I am working with OData for the first time and have a model entity with the following properties:

public IEnumerable<string> Genres { get; set; } public IEnumerable<string> GenresFiltered { get; set; } 

When I make the web call to retrieve data from the model I get the following message:

'The property 'Genres' on type 'xxxx' is not a valid property. Properties whose types are collection of primitives or complex types are not supported

Is there a way to workaround this error to display a list of strings in Odata?

2

1 Answer 1

1

Weird. I wrote a little test web api odata service and it works. The code are as below.

WebApiConfig.cs

public static class WebApiConfig { public static void Register(HttpConfiguration config) { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Foo>("Foos"); config.MapODataServiceRoute("odata", "odata", builder.GetEdmModel()); } } 

The model class

public class Foo { public string ID { get; set; } public IEnumerable<string> Genres { get; set; } } 

The controller class

public class FoosController : ODataController { // GET odata/Foos [EnableQuery] public IHttpActionResult Get() { return Ok(FakeData.GetFoos().AsQueryable()); } } 

And then I tried with http://localhost:37312/odata/Foos , the result is

{ "@odata.context": "http://localhost:37312/odata/$metadata#Foos", "value": [ { "ID": "1", "Genres": [ "aaa", "bbb" ] }, { "ID": "2", "Genres": [ "ccc" ] } ] 

}

Hope this can help.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.