c# – How to easily convert a DbDataReader object into something useful? – Education Career Blog

I am manually calling a stored procedure using an Entity Framework EntityConnection like so:

DbConnection storeConnection = entityConnection.StoreConnection;
DbCommand command = storeConnection.CreateCommand();
command.CommandText = "sp_GetMyComplexData";
command.CommandType = CommandType.StoredProcedure;

DbDataReader reader = command.ExecuteReader();

The reason for this is that the entity framework doesn’t easily support entities that don’t directly map to tables or views. I found this article (http://dotnet.dzone.com/news/mapping-stored-procedure), but it requires editing of the XML, which I would like to avoid.

In my case I’m just running a query that joins two tables using a LEFT JOIN. The reason for THAT is because I am trying to bind the results to a Telerik RadGrid, which doesn’t support hierarchical data exports, but does seem to support grouped data exports.

The problem is, how do I convert the DbDataReader object into something useful that I can bind to my RadGrid? I’ve been passing around single objects, or IQueryable objects in my DAL methods. Any ideas? Thanks in advance?


I only need the data. I don’t need to do any inserts, updates, deletes afterwards. Its a read-only view.


I don’t know about RadGrid, but you can bind that datareader to the built-in grid controls like GridView. You just can’t use it for updates, deletes, or inserts.

Otherwise, you could turn it into a datatable using the datatable’s .Load() method. But you’ll still need to know how to do the insert/update/deletes manually.

Leave a Comment