C# 小巧到数据表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17754463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dapper to DataTable
提问by user2421145
I have a scenario where I need to return a DataTable
from a query using Dapper.
How do I return a DataTable
from a query using Dapper?
我有一个场景,我需要DataTable
使用 Dapper 从查询中返回 a 。如何DataTable
使用 Dapper 从查询中返回 a ?
DataTable dt = connection.Query("SELECT * FROM table");
采纳答案by Marc Gravell
There will be no advantage whatsoeverin using dapper for a scenario involving DataSet
. And in particular, your specific example (without any parameters etc) is so trivial (not meant negatively - simply objectively) that you might as well use ExecuteReader
directly, or use a DbDataAdapter
不会有任何好处任何使用短小精悍涉及的场景DataSet
。特别是,您的具体示例(没有任何参数等)是如此微不足道(不是消极的 - 只是客观地),您不妨ExecuteReader
直接使用,或使用DbDataAdapter
I am, however, open to exposing an API on dapper that exposes the IDataReader
API from dapper - you could feed that to any consumer you want, DataSet
/ DataTable
included. But I really must question: what would be the pointin performing this example via dapper? It might make more sense if you were at least using dapper to handle parameters (I'm damned pleased with how the parameter handling worked out, truth be told).
但是,我愿意在 dapper 上公开一个 API,该IDataReader
API 从 dapper公开API - 您可以将其提供给您想要的任何消费者,DataSet
/DataTable
包括在内。但我真的必须质疑:会是什么点在通过短小精悍执行这个例子吗?如果您至少使用 dapper 来处理参数,这可能更有意义(说实话,我对参数处理的结果感到非常满意)。
回答by Vivek
Huh? Dapper only provides extension methods over ADO.NET – so that you don't have to deal with DataTables and DataSets!
嗯?Dapper 只在 ADO.NET 上提供扩展方法——这样你就不必处理 DataTables 和 DataSets!
If DataTables and DataSets are what you want – you can still use vanilla ADO.NET SqlDataAdapterwill give you all the DataTables your heart desires.
如果 DataTables 和 DataSets 是你想要的——你仍然可以使用 vanilla ADO.NET SqlDataAdapter会给你所有你心中想要的 DataTables。