1

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.

1
  • CTP5 is dead. Use EF 4.1 instead. Commented Jun 14, 2011 at 19:48

1 Answer 1

2

(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

var data = context.Database.SqlQuery<YourType>("Your SQL Query or SP call");

If you want DataSet with only returned columns you must use standard ADO.NET SqlDataAdapter or SqlConnection / SqlCommand (or version related to your database). EF doesn't like native queries which don't return fixed set of columns.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. There are just way too many columns to have them in a type. For now, I will probably go with the standard ADO.Net method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.