我在PG与字段的表需要1之间存储5.在F#方Postgres的我有这样的枚举:如何绘制F#枚举风格区分联合与Npgsql的
type PriceTier =
| P1
| P2
| P3
| P4
| P5
我直接使用npgsql,没有类型提供程序或ORM。当我发送带有参数的命令:
let build (row:CustomerRecord) =
[P("@code", row.code);.... P("@defaultPrice", row.defaultPrice);....]
我得到的错误:
The CLR type Models+PriceTier isn't supported by Npgsql or your PostgreSQL. If you wish to map it to a PostgreSQL composite type you need to register it before usage, please refer to the documentation.
所以我读http://www.npgsql.org/doc/types/enums_and_composites.html做:
NpgsqlConnection.MapEnumGlobally<PriceTier>();
但这不起作用,因为类型不一个真正的枚举,但是一个F#类型。
所以,我这里有2个问题:
- 可以使用F#类型,是无须转换为一个枚举?
- 是否可以在PriceTier - > Int之间进行映射,而无需手动进行转换?
你可以使PG表也ENUM字段? Pg是获取ENUM的F#名称,即P1,还是获得数字表示? –
你的类型定义不是一个枚举,它是一个歧视的工会 –
@Evan Carroll正在使用数字表示 – mamcx