My application features a query builder which allows users to create a SQL query with a varying select clause. I need the results to be returned in JSON by WebAPI.
There are a huge number of fields that could feature in the select.
The only approach I have found is to use:
var results = db.Database.SqlQuery<SomeObjectWhichDefinesAllPossibleFields>(sql);
return Ok(results);
Which relies on me maintaining a SomeObjectWhichDefinesAllPossibleFields class which does as it name suggests. I would like a more dynamic solution as more fields may be added in the future.
Is there another way to get WebAPI to serialize a SqlQuery with a varying select clause