如何轻松地将 DbDataReader 对象转换为有用的东西?
我使用实体框架 EntityConnection 手动调用存储过程,如下所示:
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 -procedure),但它需要编辑 XML,我想避免这样做。
就我而言,我只是运行一个使用 LEFT JOIN 连接两个表的查询。 原因是我试图将结果绑定到 Telerik RadGrid,它不支持分层数据导出,但似乎支持分组数据导出。
问题是,如何将 DbDataReader 对象转换为可以绑定到 RadGrid 的有用对象? 我一直在 DAL 方法中传递单个对象或 IQueryable 对象。 有任何想法吗? 提前致谢?
编辑:
我只需要数据。 之后我不需要做任何插入、更新、删除。 它是只读视图。
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?
EDIT:
I only need the data. I don't need to do any inserts, updates, deletes afterwards. Its a read-only view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 RadGrid,但您可以将该数据读取器绑定到 GridView 等内置网格控件。 您只是不能将其用于更新、删除或插入。
否则,您可以使用数据表的 .Load() 方法将其转换为数据表。 但您仍然需要知道如何手动执行插入/更新/删除。
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.