C#的NHibernate简单的问题 [英] C# NHibernate Simple Question
问题描述
我使用 NHibernate
-driven存储库,流利
映射并尝试使用 Linq to NHibernate
但是对于一些像这样的简单查询
检索< XValue>(x =>(x.Timestamp.CompareTo(start)> = 0&&
x.Timestamp.CompareTo end)<= 0));
//'Retrieve'在这里只是作为'session.Query< T>()。Where(expression);'
我得到以下结果:
系统.NotSupportedException:Int32 CompareTo(System.DateTime)
我不知道为什么, $ c> CompareTo 操作不会预测到数据库,输出也很奇怪:
create tableQuotUnitDescriptor(
Id整数,
PaperId INTEGER,
时间戳DATETIME,
InPaperIdx INTEGER,
主键(Id)
)
NHibernate:INSERT INTOQuotUnitDescriptor.....................
//许多INSERT的
NHibernate:选择cast(count(*)as INTEGER)作为col_0_0_
从QuotUnitDescriptorbinaryunit0_
我不明白为什么这个操作调用 select - >
NHibernate.Linq提供程序无法转换 CompareTo
调用sql。
使用类似于: / p>
检索< XValue>(x => x.Timestamp> start&& x.Timestamp< end);
P.s。并避免存储库。这是一个天真的抽象。
I'm using NHibernate
-driven repository, Fluent
mappings and attempt to use Linq to NHibernate
.
But for some simple query like this
Retrieve<XValue>(x => (x.Timestamp.CompareTo(start) >= 0 &&
x.Timestamp.CompareTo(end) <= 0 ));
// 'Retrieve' here acts simply as 'session.Query<T>().Where(expression);'
I get the following result:
System.NotSupportedException: Int32 CompareTo(System.DateTime)
I don't know why, but CompareTo
operations aren't projected to the database and the output is also kind of weird:
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_
I can't understand why this operation invokes a select -> integer
operation.
How should the following date-oriented query be implemented? (using Linq
is better, but criterias are also fine, I think).
NHibernate.Linq provider is unable to transform CompareTo
call to sql.
Use something like:
Retrieve<XValue>(x => x.Timestamp>start && x.Timestamp<end);
P.s. and avoid repositories. That's a naive abstraction.
这篇关于C#的NHibernate简单的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!