how to run simple ODATA query dynamically and return result in json format using with Roslyn?

367 views Asked by At

I'm working on query builder for simple Odata

I'm generating simple odata queries dynamically and want to show result of queries on json format.

query text:

   var DetailData = await myClient.For<CustomerDetail>().Filter(q => q.Id == id).OrderBy(q => q.Key).FindEntriesAsync();

how to run simple ODATA query dynamically and return result in json format?

1

There are 1 answers

1
lukehellrunner On BEST ANSWER

Where do you want to return the JSON data?

If you are using ASP.NET WebAPI, you might return the CustomerDetail list directly and the framework will serialize it as XML or JSON, depending on what the client requested.

If you need to serialize your objects into a JSON-string, you might use the Json.Net library (http://www.newtonsoft.com/json, also available as a NuGet package)