I am working on an ASP.NET MVC application. This application executes a query via JQuery. The result set is returned as JSON from my ASP.NET MVC controller. Before I return the serialized result set, i need to trim it down to only the properties I need. To do this, I’m using a LINQ Query. That LINQ Query looks like the following:
private IEnumerable RefineResults(ResultList<Result> results)
{
// results has three properties: Summary, QueryDuration, and List
var refined = results.Select(x => new
{
x.ID, x.FirstName, x.LastName
});
return refined;
}
When I execute this method, I’ve noticed that refined does not include the Summary and Duration properties from my original query. I’m want my result set to be structured like:
Summary
QueryDuration
Results
- Result 1
- Result 2
- Result 3
...
At this time, when I execute RefineResults, I get the result list I would expect. However, I can’t figure out how to put those entries in a property called “Results”. I also don’t know how to add the “Summary” and “QueryDuration” properties.
Can someone please point me in the right direction?
Thanks!
You will probably want to create a specific DTO class for the return value of this function.