[英]Cannot execute query because datetime won't be converted to string c#/MSSQL
I have this attempt to execute a query: 我有这种尝试执行查询:
hmrSingle = dbMngr.Set<HistoryMessagesRequested>().Where(x => x.dateregistration == msgv.DtRicezione && x.val == msgv.value && x.parameter == dmf.Description && x.DeviceID == ms.IDDevice).FirstOrDefault();
dateregistration
and DtRicezione
are both declared as DateTime?
dateregistration
和DtRicezione
都声明为DateTime?
into the database context and they're "datetime" into MSSQL tables too. 进入数据库上下文,它们也“日期时间”进入MSSQL表。
I can't figure out why this problem is continuously present. 我不知道为什么这个问题持续存在。
Any time you are using a nullable value type you need to use .value to get its value. 每当您使用可为空的值类型时,都需要使用.value来获取其值。 Try:
尝试:
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.