iT邦幫忙

0

C# EntityFramework Jsonb 和 Dictionary 查詢問題

Ks 2019-03-29 11:45:411635 瀏覽

我有一個Table的Column設定為Jsonb的類型,裡面會紀錄一些userid之類的參數,
這個column會mapping到Dictionary<string,string>.
Database: postgresql

請問該如何用entity framework查詢這個欄位,
我使用以下的條件式查詢,但是視乎一直出現
could not be translated and will be evaluated locally.
產生出來的SQL指令如下,
條件指令:
(string.IsNullOrWhiteSpace(userId) ? true : x.To["userid"] == userId)

(IIF(__IsNullOrWhiteSpace_4, True, ([x].UserId == __userId_5)) OrElse IIF(__IsNullOrWhiteSpace_6, True, (Invoke(___mapper_7, [x]).To.get_Item("userid") == __userId_8))))' could not be translated and will be evaluated locally.

【已解決】
最後使用Dapper來讀取資料

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
小魚
iT邦大師 1 級 ‧ 2019-03-29 13:27:35

x.To["userid"].ToString() 試試

Ks iT邦新手 3 級 ‧ 2019-03-29 15:21:55 檢舉
(IIF(__IsNullOrWhiteSpace_4, True, ([x].UserId == __userId_5)) OrElse IIF(__IsNullOrWhiteSpace_6, True, (Invoke(___mapper_7, [x]).To.get_Item("userid").ToString() == __userId_8))))

謝謝,視乎還是不行。

Ks iT邦新手 3 級 ‧ 2019-04-01 23:04:46 檢舉

感謝答覆,研究了一段時間,發現Entity Framework似乎無法去這樣where jsonb的column,而且也做不到Index的效用,所以打算直接用Dapper 或者其他SQL Raw直接執行./images/emoticon/emoticon67.gif

我要發表回答

立即登入回答