簡體   English   中英

無法執行查詢,因為datetime不會轉換為字符串c#/ MSSQL

[英]Cannot execute query because datetime won't be converted to string c#/MSSQL

我有這種嘗試執行查詢:

 hmrSingle = dbMngr.Set<HistoryMessagesRequested>().Where(x => x.dateregistration == msgv.DtRicezione && x.val == msgv.value && x.parameter == dmf.Description && x.DeviceID == ms.IDDevice).FirstOrDefault();

dateregistrationDtRicezione都聲明為DateTime? 進入數據庫上下文,它們也“日期時間”進入MSSQL表。

我不知道為什么這個問題持續存在。

每當您使用可為空的值類型時,都需要使用.value來獲取其值。 嘗試:

hmrSingle = dbMngr.Set<HistoryMessagesRequested>().Where(x => x.dateregistration.value == msgv.DtRicezione.value && x.val == msgv.value && x.parameter == dmf.Description && x.DeviceID == ms.IDDevice).FirstOrDefault();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM