Reputation: 5550
I have a project in MVC3 ADO.NET using Visual Studio 2010 and C#. I have a requirement for adhoc reports which are held in a database table (two columns - the report title and the SQL script to be executed to return the report). The resultant report can then either be displayed in a table or downloaded as a CSV file.
I want to execute the SQL script using EF but I do not know in advance what the entity to be returned is, for example, how many fields will be returned from the query. The 'best' method seems to be using something like:
var QueryResults = dataContext.ExecuteStoreQuery<object>(SQLText, String.Empty);
but then I need to use some reflection to get the report structure which is just a set of strings. This feels like a round about way of doing things and I'm not sure how to get the field/column names from the returned results.
If I were to use an ADO.NET SqlDataReader then I would now exactly what to do, but that feels like a backward step.
Quick reports using an SQL script loaded at run time is a powerful feature I have used in the past but I would like to bring it into the EF era.
Is there a straightforward way of doing this?
Upvotes: 0
Views: 1053
Reputation: 11964
You should use SqlDataReader for your task. There will be no advantages in using EF in this task due to untyped result of your query.
Upvotes: 2