C#NHibernate简单问题

Yip*_*Yay 2 c# nhibernate fluent-nhibernate

我正在使用NHibernate-driven存储库,Fluent映射并尝试使用Linq to NHibernate.

但对于像这样的一些简单查询

Retrieve<XValue>(x => (x.Timestamp.CompareTo(start) >= 0 &&
                       x.Timestamp.CompareTo(end) <= 0 ));

// 'Retrieve' here acts simply as 'session.Query<T>().Where(expression);'
Run Code Online (Sandbox Code Playgroud)

我得到以下结果:

System.NotSupportedException: Int32 CompareTo(System.DateTime)
Run Code Online (Sandbox Code Playgroud)

我不知道为什么,但CompareTo操作不会投射到数据库,输出也有点奇怪:

create table "QuotUnitDescriptor" (
    Id  integer,
   PaperId INTEGER,
   Timestamp DATETIME,
   InPaperIdx INTEGER,
   primary key (Id)
)

NHibernate: INSERT INTO "QuotUnitDescriptor" ......................

// Many INSERT's

NHibernate: select cast(count(*) as INTEGER) as col_0_0_ 
    from "QuotUnitDescriptor" binaryunit0_
Run Code Online (Sandbox Code Playgroud)

我无法理解为什么这个操作会调用一个select -> integer操作.

如何实现以下面向日期的查询? (使用Linq更好,但我认为标准也很好).

Arn*_*psa 5

NHibernate.Linq提供程序无法将CompareTo调用转换为sql.

使用类似的东西:

Retrieve<XValue>(x => x.Timestamp>start && x.Timestamp<end);
Run Code Online (Sandbox Code Playgroud)

Ps并避免存储库.这是一个天真的抽象.