如何轻松转换的DbDataReader对象转换成有用的东西? [英] How to easily convert a DbDataReader object into something useful?
问题描述
我手动调用使用实体框架EntityConnection像一个存储过程,:
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();
这样做的原因是,实体框架不容易支持不直接映射实体为表或视图。我发现这篇文章( http://dotnet.dzone.com/news/mapping-stored-程序),但它需要的XML,我想避免的编辑。
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.
在我的情况下,我只是运行联接两个查询使用LEFT JOIN表。这样做的原因是因为我想结合的结果,一个Telerik的radgrid控件,它不支持分层的数据出口,但似乎并支持分组数据的出口。
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.
问题是,我怎么转换DbDataReader对象转换成我可以绑定到我的radgrid控件有用的东西?我一直在通过我的DAL方法围绕单个对象或IQueryable的对象。有任何想法吗?在此先感谢
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.
推荐答案
我不知道radgrid控件,但可以说的DataReader绑定到内置在网格控件一样的GridView。你不能用它来更新,删除或插入。
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.
否则,你可以使用DataTable的.Load()方法,把它变成一个DataTable。但你仍然需要知道如何做的插入/更新/删除手动
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.
这篇关于如何轻松转换的DbDataReader对象转换成有用的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!