简体   繁体   中英

Entity Framework Core PostgreSQL hstore queries

I need generate query for value in hstore column

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)

But is no best way, exist any way to realize this query to translate to this sql?

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

The Npgsql EFCore provider doesn't currently do any translations for the hstore type. This is mainly because extended support is already present for the PostgreSQL jsonb type (including what you want to do), and that type is much more powerful than hstore. Consider switching from hstore to jsonb.

This is the issue tracking query translation for hstore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM