0
以下のクエリでは、要求された日付範囲内にある割り当てを持つEmployeeオブジェクトが返されます。hqlクエリで大量のデータを取り込む
クエリはすべての割り当てを返します。また、データベースに3つのクエリを実行していますが、わかりません(第3のバッチサイズはアクティビティ科目に100というバッチサイズがあるためです)。
要求された期間の割り当てだけを効率的に返すようにこのクエリを変更するにはどうすればよいですか?
乾杯、
Berryl
DATABASE SQL文:
NHibernate: select resource0_.ResourceId as ResourceId0_, resource0_.BusinessId as BusinessId0_, resource0_.ResourceName as Resource4_0_, resource0_.OwnerName as OwnerName0_, resource0_.EmployeeNumber as Employee6_0_, resource0_.FirstName as FirstName0_, resource0_.LastName as LastName0_, resource0_.DepartmentId as Departme9_0_, resource0_.ResourceType as Resource2_0_ from Resources resource0_
inner join Allocations allocation1_ on resource0_.ResourceId=allocation1_.ResourceId
where [email protected]
and (allocation1_.StartTime between @p1 and @p2);@p0 = '000001' [Type: String (0)], @p1 = 12/27/2010 12:00:00 AM [Type: DateTime (0)], @p2 = 1/2/2011 11:59:59 PM [Type: DateTime (0)]
NHibernate: SELECT allocation0_.ResourceId as ResourceId1_, allocation0_.AllocationId as Allocati1_1_, allocation0_.AllocationId as Allocati1_2_0_, allocation0_.ActivitySubjectId as Activity2_2_0_, allocation0_.ResourceId as ResourceId2_0_, allocation0_.StartTime as StartTime2_0_, allocation0_.EndTime as EndTime2_0_, allocation0_.PostingTime as PostingT6_2_0_
FROM Allocations allocation0_ WHERE [email protected];@p0 = 98304 [Type: Int32 (0)]
NHibernate: SELECT activitysu0_.ActivitySubjectId as Activity1_3_0_, activitysu0_.BusinessId as BusinessId3_0_, activitysu0_.Description as Descript4_3_0_, activitysu0_.ActivitySubjectType as Activity2_3_0_
FROM ActivitySubjects activitysu0_ WHERE activitysu0_.ActivitySubjectId in (@p0, @p1, @p2, @p3);@p0 = 32784 [Type: Int32 (0)], @p1 = 32854 [Type: Int32 (0)], @p2 = 32860 [Type: Int32 (0)], @p3 = 32861 [Type: Int32 (0)]
HQL QUERY
public Resource GetResourceForDateRange<T>(string businessId, DateRange period) where T : Resource
{
Check.RequireStringValue(businessId, "businessId");
Check.RequireNotNull(period);
const string hql =
@"
select r
from Resource r
inner join r.Allocations as a
where r.BusinessId = :businessId
and a.TimeRange.StartTime between :periodStart and :periodEnd";
return _session.CreateQuery(hql)
.SetString("businessId", businessId)
.SetDateTime("periodStart", period.Start)
.SetDateTime("periodEnd", period.End)
.UniqueResult<Resource>();
}
MAPPING
<id name="Id" type="System.Int32" unsaved-value="0">
<column name="ResourceId" />
<generator class="hilo" />
</id>
<discriminator column="ResourceType" type="System.String" />
<property name="BusinessId" length="50" not-null="true" unique="true" unique-key="DomainSignature" index="ResourceDomainSignature" />
<property name="ResourceName" length="75" not-null="true" />
<property name="OwnerName" length="75" not-null="true" />
<set access="field.camelcase-underscore" cascade="all-delete-orphan" inverse="true" name="Allocations">
<key foreign-key="Allocations_Resource_FK">
<column name="ResourceId" />
</key>
<one-to-many class="Allocations.Allocation" />
</set>
<subclass name="Resources.HumanResources.Employee" discriminator-value="EMPLOYEE">
...
</subclass>
遅延ロードがオフではなく、フェッチが戻って期待される結果と一緒に1つのクエリにそれを得た。やってみありがとう! – Berryl
歓迎しますが、回答を受け入れたとマークすることを忘れないでください。 – Vadim