Npgsql 枚举错误 [英] Npgsql Enum Error

查看:66
本文介绍了Npgsql 枚举错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用 Npgsql V3.05 持久化枚举时收到以下错误消息.

I am getting the following error message when trying to persist an enumeration using Npgsql V3.05.

枚举必须通过 Connection.RegisterEnumType 或 RegisterEnumTypeGlobally 向 Npgsql 注册

Enums must be registered with Npgsql via Connection.RegisterEnumType or RegisterEnumTypeGlobally

我在 PostgrSQL 中的 PostgreSQL 中创建了一个类型,并使用以下查询对其进行了验证:

I created a type in PostgreSQL in PostgrSQL, and verified it with following query:

select enum_range(null::schedule_link_type);

哪个返回

"{finish_to_start,finish_to_finish,start_to_start,start_to_finish}"

我在我的 VB.NET 程序中创建了一个枚举(注意这是在我的 ActionRecord 类中):

I created an enum in my VB.NET program as (note that this is in my ActionRecord class):

Public Enum ScheduleLinkType
    <EnumLabel("finish_to_start")>
    FinishToStart
    <EnumLabel("finish_to_finish")>
    FinishToFinish
    <EnumLabel("start_to_finish")>
    StartToFinish
    <EnumLabel("start_to_start")>
    StartToStart
End Enum

我在运行插入查询之前调用了以下方法(注意我设置了一个断点并确认这确实是在执行插入命令之前被调用的):

I call the following method before running the insert query (note that I set a breakpoint andconfirmed this is really being called before the insert command is executed):

NpgsqlConnection.RegisterEnumGlobally(Of ActionRecord.ScheduleLinkType)("schedule_link_type")

我尝试插入的字段参数是(来自 Visual Studio 调试器观察窗口):

The parameter for field that I am trying to insert is (from the Visual Studio debugger watch window):

command.Parameters(1)   {Npgsql.NpgsqlParameter}    Npgsql.NpgsqlParameter
    Collection  {Npgsql.NpgsqlParameterCollection} Npgsql.NpgsqlParameterCollection
    DbType  Object {13} System.Data.DbType
    Direction   Input {1}   System.Data.ParameterDirection
    EnumType    {Name = "ScheduleLinkType" FullName = "VSData.ActionRecord+ScheduleLinkType"}   System.Type {System.RuntimeType}
    IsNullable  False   Boolean
    NpgsqlDbType    Enum {47}   NpgsqlTypes.NpgsqlDbType
    NpgsqlValue FinishToFinish {1}  Object {VSData.ActionRecord.ScheduleLinkType}
    ParameterName   "link_type" String
    Precision (System.Data.Common.DbParameter)  0   Byte
    Precision   0   Byte
    Scale (System.Data.Common.DbParameter)  0   Byte
    Scale   0   Byte
    Size    0   Integer
    SourceColumn    ""  String
    SourceColumnNullMapping False   Boolean
    SourceVersion   Current {512}   System.Data.DataRowVersion
    Value   FinishToFinish {1}  Object {VSData.ActionRecord.ScheduleLinkType}

有人知道为什么这不起作用吗?

Anybody know why this is not working?

推荐答案

由于某种原因,这个问题已经消失了,现在一切都按预期工作了(请注意,自从发布原始问题以来,我已将 NPGSQL 更新到 3.1.8,但是我没有注意到这个问题是因为升级还是我改变的其他东西而消失了).

This issue has gone away for some reason, and everything works as expected now (note that I have updated NPGSQL to 3.1.8 since posting the original question, but I did not notice if this problem went away due to the upgrade or something else I changed).

这篇关于Npgsql 枚举错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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