Skip to content
Advertisement

Anonymous type result from sql query execution entity framework

I am using entity framework 5.0 with .net framework 4.0 code first approach. Now i know that i can run raw sql in entity framework by following

It’s working perfectly but what I want is return anonymous results. For example I want only specific columns from student table like following

It is not working. it gives exception

The data reader is incompatible with the specified ‘MyApp.DataContext.Student’. A member of the type, ‘StudentId’, does not have a corresponding column in the data reader with the same name.

So I have tried dynamic type

it is also not working, it returns an empty object. No data available in it.

Is there any way to get anonymous type result from a dynamic SQL query?

Advertisement

Answer

Here is final solution that worked fine for me.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement