需要来自criteriaQuery-->帮助的nhibernate NamedQuery
我试图将工作条件查询转换为命名查询,但语法不正确。hql版本显然需要指定类型和id参数 查询是在一个类上进行的,该类还映射了下面的任何 谁能帮我把语法弄好吗 干杯, 贝里尔 工作条件查询 任何有效的映射都可以! 命名查询到目前为止不起作用 我认为这是hql语法,但错误消息说缺少参数需要来自criteriaQuery-->帮助的nhibernate NamedQuery,nhibernate,hql,nhibernate-criteria,named-query,any,Nhibernate,Hql,Nhibernate Criteria,Named Query,Any,我试图将工作条件查询转换为命名查询,但语法不正确。hql版本显然需要指定类型和id参数 查询是在一个类上进行的,该类还映射了下面的任何 谁能帮我把语法弄好吗 干杯, 贝里尔 工作条件查询 任何有效的映射都可以! 命名查询到目前为止不起作用 我认为这是hql语法,但错误消息说缺少参数 .... select a from Allocation a where a.Resource = :resource an
....
select a
from Allocation a
where a.Resource = :resource
and a.TimeRange.StartTime between :periodStart and :periodEnd
order by a.TimeRange.StartTime
....
return _session.GetNamedQuery("FetchByResourceForDateRange")
.SetEntity("resource", resource)
.SetDateTime("periodStart", searchRange.Start)
.SetDateTime("periodEnd", searchRange.End)
.List<Allocation>();
NHibernate.Exceptions.GenericADOException : could not execute query
[ select allocation0_.AllocationId as Allocati1_2_, allocation0_.ResourceType as Resource2_2_, allocation0_.ResourceId as ResourceId2_, allocation0_.ActivityType as Activity4_2_, allocation0_.ActivityId as ActivityId2_, allocation0_.StartTime as StartTime2_, allocation0_.EndTime as EndTime2_, allocation0_.PostingTime as PostingT8_2_ from Allocations allocation0_ where allocation0_.ResourceType=@p0 and allocation0_.ResourceId=@p1 and (allocation0_.StartTime between @p2 and @p3) order by allocation0_.StartTime ]
Name:resource - Value:George Washington 000001 Name:periodStart - Value:3/14/2011 12:00:00 AM Name:periodEnd - Value:3/20/2011 11:59:59 PM
[SQL: select ...
from Allocations allocation0_
where allocation0_.ResourceType=@p0 and allocation0_.ResourceId=@p1 and (allocation0_.StartTime between @p2 and @p3)
order by allocation0_.StartTime]
----> System.Data.SQLite.SQLiteException : SQLite error
Insufficient parameters supplied to the command
使现代化
这个组合执行,但给出了错误的答案。还不知道它离我需要的东西是近还是远
select a
from Allocation a
where a.Resource.class = :class and a.Resource.id = :id
and a.TimeRange.StartTime between :periodStart and :periodEnd
order by a.TimeRange.StartTime
return _session.GetNamedQuery("FetchByResourceForDateRange")
.SetString("class", typeof(Resource).FullName)
.SetInt32("id", resource.Id)
.SetDateTime("periodStart", searchRange.Start)
.SetDateTime("periodEnd", searchRange.End)
.List<Allocation>();
好的,根据NHib开发负责人Fabio Maulo的说法: 您必须使用元数据值,而不是typeofentity.FullName 因此,在我的案例中,以下是我最后一次使用hql:
return _session.GetNamedQuery("FetchByResourceForDateRange")
.SetString("class", "EMPLOYEE")
.SetInt32("id", resource.Id)
.SetDateTime("periodStart", searchRange.Start)
.SetDateTime("periodEnd", searchRange.End)
.List<Allocation>();
比我希望的要难看一点,但我会接受:-
嗯,,
贝里尔
select a
from Allocation a
where a.Resource.class = :class and a.Resource.id = :id
and a.TimeRange.StartTime between :periodStart and :periodEnd
order by a.TimeRange.StartTime
return _session.GetNamedQuery("FetchByResourceForDateRange")
.SetString("class", typeof(Resource).FullName)
.SetInt32("id", resource.Id)
.SetDateTime("periodStart", searchRange.Start)
.SetDateTime("periodEnd", searchRange.End)
.List<Allocation>();
return _session.GetNamedQuery("FetchByResourceForDateRange")
.SetString("class", "EMPLOYEE")
.SetInt32("id", resource.Id)
.SetDateTime("periodStart", searchRange.Start)
.SetDateTime("periodEnd", searchRange.End)
.List<Allocation>();