[英]ObjectQuery, passing Time in Where clause
How can I construct the Where clause of the ObjectQuery where I will be querying for the Time part only of a DateTime column? 如何构造ObjectQuery的Where子句,仅在其中查询DateTime列的Time部分? I've tried the following but it's not working.
我已经尝试了以下方法,但是没有用。 I get an invalid exception on Convert.
我在Convert上收到无效的异常。
ObjectQuery<Item> _Query = ItemEntities.CreateQuery<Item>("Item");
_Query = _Query.Where("Convert(VARCHAR,it.START_TIME,114) > '{0}'", startTime.TimeOfDay);
Also, I'm using Oracle as database. 另外,我正在使用Oracle作为数据库。 So I tried
to_char
instead of convert and still I get the same error. 因此,我尝试使用
to_char
而不是convert,但仍然遇到相同的错误。
Thanks. 谢谢。
You should be able to get the time portion from the date using TO_CHAR
and then subsequently converting it to a system type eg 您应该能够使用
TO_CHAR
从日期中获取时间部分,然后将其转换为系统类型,例如
TO_DATE(TO_CHAR(it.START_TIME,'HH24:MI:SS'), 'hh24:mi:ss') from dual
If ObjectQuery
doesn't support TO_CHAR
you try using Extract
and build up the time manually eg 如果
ObjectQuery
不支持TO_CHAR
请尝试使用Extract
并手动建立时间,例如
TO_DATE(EXTRACT(HOUR FROM it.START_TIME) || ':' || EXTRACT(MINUTE FROM it.START_TIME) || ':' || EXTRACT(SECOND FROM it.START_TIME) FROM DUAL, 'HH24:MI:SS');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.