我在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