我有一个 NHibernate 标准查询,如下所示:
using (var unitOfWork = this.UnitOfWorkFactory.CreateUnitOfWork())
{
const string fromstring = "2013-01-29 23:30:33.5993";
var from = DateTime.Parse(fromstring);
const string tostring = "2013-01-29 23:30:33.63434";
var to = DateTime.Parse(tostring);
var criteria = unitOfWork.Session.CreateCriteria<DataModel>();
criteria.Add(Restrictions.Ge("Created", from));
criteria.Add(Restrictions.Le("Created", to));
items = criteria.List<DataModel>();
}
我正在使用 Postgresql,这是表映射:
-- Table: data
-- DROP TABLE data;
CREATE TABLE data
(
id integer NOT NULL DEFAULT nextval('data__sequence'::regclass),
created timestamp without time zone NOT NULL,
CONSTRAINT itemsupdatelog_pkey PRIMARY KEY (id )
)
WITH (
OIDS=FALSE
);
ALTER TABLE data
OWNER TO ubuntu;
和 NHibernate 映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Data" namespace="Data.Models">
<class name="DataModel" table="Data" mutable="false">
<id name="Id">
<generator class="sequence">
<param name="sequence">Data__Sequence</param>
</generator>
</id>
<property name="Created" not-null="true" type="Timestamp" />
</class>
</hibernate-mapping>
我可以确认表中的数据看起来不错(即,所有 Created 值肯定有毫秒,当我使用 NHibernate 查询数据库的值 OUT 时,DateTime 对象具有正确的毫秒)。
但是,当我使用 NHProf 检查查询时,NHibernate 不会在查询中发送正确的毫秒数:
SELECT this_.Id as Id1_0_,
this_.Created as Created1_0_,
FROM Data this_
WHERE this_.Created >= '2013-01-29T23:30:33.00' /* :p1 */
and this_.Created <= '2013-01-29T23:30:33.00' /* :p2 */
ORDER BY this_.Created desc
有任何想法吗?