criteriaqueryから名前が付けられたnhibernate->必要なヘルプ
-
26-10-2019 - |
質問
作業基準クエリを名前付きクエリに変換しようとしていますが、構文を正しく取得していません。 HQLバージョンでは、明らかに指定されたタイプとIDの両方のパラメーションが必要です。
クエリは、任意のものでマッピングされたクラスを超えています(以下も)
誰かが私に手を差し伸べて構文を正しく手に入れてもらえますか?
乾杯、
ベリー
動作基準クエリ
result = _session
.CreateCriteria<Allocation>()
.Add(Restrictions.Eq(propName_Resource, resource))
.Add(Restrictions.Between(propName_StartTime, (DateTime)searchRange.Start, (DateTime)searchRange.End))
.AddOrder(Order.Asc(propName_StartTime))
.List<Allocation>();
produces
SELECT this_.AllocationId as Allocati1_2_0_, this_.ResourceType as Resource2_2_0_, this_.ResourceId as ResourceId2_0_, this_.ActivityType as Activity4_2_0_,
this_.ActivityId as ActivityId2_0_, this_.StartTime as StartTime2_0_, this_.EndTime as EndTime2_0_, this_.PostingTime as PostingT8_2_0_
FROM Allocations this_
WHERE this_.ResourceType = @p0 and this_.ResourceId = @p1 and this_.StartTime between @p2 and @p3 ORDER BY this_.StartTime asc;@p0 = 'EMPLOYEE' [Type: String (0)], @p1 = 98304 [Type: Int32 (0)], @p2 = 3/14/2011 12:00:00 AM [Type: DateTime (0)], @p3 = 3/20/2011 11:59:59 PM [Type: DateTime (0)] 2011-03-14 Mon - 2011-03-20 Sun
任意のマッピング(機能します!)
<any name="Resource" cascade="all" id-type="System.Int32" meta-type="System.String"
>
<meta-value value="EMPLOYEE" class="Employee, ..." />
<meta-value value="Facility" class="Facility, ..." />
<column name="ResourceType"/>
<column name="ResourceId"/>
</any>
これまでに名前が付けられたクエリ(動作していません)
私 考える これはHQLの構文ですが、エラーメッセージがPARAMが欠落していると書かれています
....
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>();
解決
OK、ファビオ・マウロごと、nhibのリード開発者:
「Typeof(Entity).fullnameではなく、メタデータの値を使用する必要があります」
だから私の場合、以下は最後のhqlを作りました私は仕事をしました:
return _session.GetNamedQuery("FetchByResourceForDateRange")
.SetString("class", "EMPLOYEE")
.SetInt32("id", resource.Id)
.SetDateTime("periodStart", searchRange.Start)
.SetDateTime("periodEnd", searchRange.End)
.List<Allocation>();
私が期待していたよりも少しugいものですが、私はそれを取ります: - )
Hth、
ベリー
所属していません StackOverflow