实体框架核心PostgreSQL hstore查询

时间:2020-05-19 19:41:38

标签: postgresql npgsql hstore ef-core-3.1

我需要在hstore列中生成值查询

var collection = await _context.Settings
.Select(b => new
{
    SettingId = b.SettingId,
    SettingParentId = b.SettingParentId,
    SettingValue = (b.SettingValue.ContainsKey('key') ? b.SettingValue['key'] : "")
})
.OrderBy(x => x.SettingId)

但是不是最好的方法,是否存在实现该查询以转换为该sql的任何方法?

SELECT setting_id, 
       setting_parent_id,
       setting_value -> 'key' AS setting_value
FROM settings

1 个答案:

答案 0 :(得分:2)

Npgsql EFCore提供程序当前不对hstore类型进行任何转换。这主要是因为for the PostgreSQL jsonb type已经提供了扩展支持(包括您要执行的操作),并且该类型比hstore强大得多。考虑从hstore切换到jsonb。

This is the issue跟踪hstore的查询翻译。