简体   繁体   English

我可以从 Dapper 查询中获取字段结构吗?

[英]Can I get the field structure from a Dapper query?

I've been looking through the source code, but there is a fair amount going on for such a small ORM.我一直在查看源代码,但是对于这么小的 ORM,有很多事情要做。 Is there any way to retrieve the field structure of a query returned by Dapper after calling .Query()?有没有办法在调用 .Query() 后检索 Dapper 返回的查询的字段结构? Essentially I need the same data as returned by a DataReader when you call GetSchemaTable().本质上,当您调用 GetSchemaTable() 时,我需要与 DataReader 返回的数据相同的数据。

This can be done as follows:这可以按如下方式完成:

Fetch the reader using either of the following calls:使用以下任一调用获取读取器:

IDataReader dr = _connection.ExecuteReader(sql)

or或者

IDataReader dr = _connection.GetStream(sql)

Now you can call dr.GetSchemaTable() to get the relevant schema DataTable In fact you may typecast the same to relevant DbDataReader type like SqlDataReader or OracleDataReader in case you want to utilize an overload of a GetSchemaTable()现在您可以调用dr.GetSchemaTable()来获取相关的模式DataTable事实上,如果您想利用GetSchemaTable()的重载,您可以将相同的类型转换为相关的DbDataReader类型,如SqlDataReader or OracleDataReader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM