I’m using EF code first approach in my application. I need to execute a query which runs a report and returns the result set with dynamically generated fields. The fields in the result set can be different based on the condition. Is it possible to return a result set using code first approach like maybe in a DataSet, or is there any other way to achieve this?
Thanks.
(Untested) You can try to define data type which will have properties for all possible columns your query can return. It must be flat type with no nested objects and properties must have same names as columns in result set. Then you can use
If you want
DataSetwith only returned columns you must use standard ADO.NETSqlDataAdapterorSqlConnection/SqlCommand(or version related to your database). EF doesn’t like native queries which don’t return fixed set of columns.