繁体   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