我如何使用npgsql 3.0.0读取Postgresql Citext字段? [英] Ho do I read a postgresql citext field with npgsql 3.0.0?

查看:167
本文介绍了我如何使用npgsql 3.0.0读取Postgresql Citext字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在postgresql中有一个名为 exampletable的表,其中包含100个citext类型的字段,我们将其称为 field1, field2等...如何使用npgsql读取这些字段?理想情况下,我想使用以下sql:

Say I have a table called "exampletable" in postgresql with a 100 citext typed fields, let's call them "field1", "field2" etc... How do I read these fields using npgsql? Ideally I would like to use the following sql:

select * from exampletable

但是当我使用npgsql 3.0.0执行sql时,得到以下 NotSupportedException

But when I execute the sql using npgsql 3.0.0 I get the following NotSupportedException:


字段field1具有Npgsql当前未知的类型(OID 16466)。您可以通过将其标记为未知来将其检索为字符串,请参见常见问题...。

"The field field1 has a type currently unknown to Npgsql (OID 16466). You can retrieve it as a string by marking it as unknown, please see the FAQ..."

要克服这一点,我可以将所有字段手动转换为sql查询中的文本,如下所示:

To overcome this I could manually cast all the fields to text in the sql query like so:

select field1::text, field2::text, ... field99::text, field100::text from exampletable

如您所见,这是非常冗长和繁琐的。我是否必须手动将所有字段都强制转换为查询中的文本,或者是否有一些更简单的方法来配置npgsql以允许在传输中使用citext类型?我将如何在Postgresql中处理其他非标准扩展类型?

As you can see this is extremely verbose and cumbersome. Would I have to manually cast all fields to text in my query or is there some easier way to configure npgsql to allow citext types in the transfer? How would I handle other non-standard extension types in postgresql?

任何帮助将不胜感激。

奖金问题:我尝试查找异常消息中引用的FAQ,但未找到任何内容。您知道消息所引用的页面吗?

Bonus question: I have tried finding the FAQ referenced in the exception message but I have failed to find anything. Do you know what page the message is referencing?

推荐答案

抱歉,该类型一定已经漏过了。我为此打开了一个问题,并将在3.0.1中实现。

Apologies, that type must have slipped through the cracks. I've opened an issue for it and will implement for 3.0.1.

同时,您可以在倒下时手动进行强制转换,或将NpgsqlCommand的AllResultTypesAreUnknown设置为true。这将使Npgsql请求文本中所有结果集的列,然后可以访问它们。常见问题解答仍在进行中,尚未在线发布,为此深表歉意。

In the meantime, you can either cast manually as you're down, or set your NpgsqlCommand's AllResultTypesAreUnknown to true. This will make Npgsql request all the resultset's columns in text, which you can then access. The FAQ is still in progress and not yet online, apologies for that as well.

这篇关于我如何使用npgsql 3.0.0读取Postgresql Citext字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆