NHibernateは基準を使用したインラインビューをサポートしていますか?Googleは関連する結果を返さないようです。これが、できれば基準を使用して変換する必要があるクエリです。
SELECT COUNT (incident_count) AS incident_count,
SUM (total_customers) AS total_customers,
MAX (longest_etr) AS longest_etr,
COUNT (DISTINCT crew_count) AS crew_count
FROM (SELECT l.incident_id AS incident_count,
i.downstream_cust_qty_total AS total_customers,
TO_CHAR (MAX (l.etr_datetime),
'MM/DD/YYYY HH24:mi:ss'
) AS longest_etr,
ca.crew_no AS crew_count
FROM district d,
LOCATION l,
ZONE z,
incident_device ID,
incident i,
crew_action ca
WHERE l.dist_no = d.dist_no
AND d.zone_id NOT IN (1008, 1010)
AND ID.location_id = l.location_id
AND ID.incident_id = i.incident_id
AND l.location_id = i.location_id
AND ca.incident_id = i.incident_id
AND ca.location_id = l.location_id
AND ID.call_type_cd IN ('ELEC', 'PLAN')
AND ID.clue_cd NOT IN (248, 258, 975)
AND l.fac_job_status_cd IN ('A', 'D', 'F', 'G', 'P', 'U', 'W')
AND z.zone_id = d.zone_id
AND ca.crew_action_id = l.crew_action_id
AND l.dist_no = 24
AND l.primary_loc_flg = 'T'
GROUP BY l.incident_id, i.downstream_cust_qty_total, ca.crew_no)
where句ですでにすべてが変換されています。その部分は問題ありませんでした。これは次のようなものに変換されます。
GetSession().CreateCriteria(typeof (Incident), () => incidentAlias)
// Projection
.SetProjection(
Projections.ProjectionList()
.Add(LambdaProjection.Count<Incident>(i => incidentAlias.IncidentId).As(() => IncidentCount))
.Add(LambdaProjection.Sum<Incident>(i => incidentAlias.DownstreamCustQtyTotal).As(() => TotalCustomers))
.Add(LambdaProjection.Max<Location>(l => locationAlias.EtrDatetime).As(() => LongestEtr))
.Add(LambdaProjection.CountDistinct<CrewAction>(ca => crewActionAlias.CrewNo).As(() => CrewCount))
.Add(LambdaProjection.GroupProperty(() => incidentAlias.IncidentId))
.Add(LambdaProjection.GroupProperty(() => incidentAlias.DownstreamCustQtyTotal))
.Add(LambdaProjection.GroupProperty(() => crewActionAlias.CrewNo))
)
// Aliases
.CreateAlias(() => incidentAlias.Locations, () => locationAlias)
.CreateAlias(() => incidentAlias.IncidentDevices, () => incidentDeviceAlias)
.CreateAlias(() => incidentAlias.District, () => districtAlias)
.CreateAlias(() => districtAlias.Zone, () => zoneAlias)
.CreateAlias(() => locationAlias.CrewAction, () => crewActionAlias)
// Criterias
.Add(() => locationAlias.PrimaryLocFlg == "T")
.Add(() => locationAlias.DistNo == districtNumber)
.Add(() => zoneAlias.ZoneId != 1008)
.Add(() => zoneAlias.ZoneId != 1010)
.Add(SqlExpression.In(() => locationAlias.FacJobStatusCd, new[] { "A", "D", "F", "G", "P", "U", "W" }))
.Add(SqlExpression.In(() => incidentDeviceAlias.CallTypeCd, new [] { "ELEC", "PLAN" }))
.Add(() => incidentDeviceAlias.ClueCd != "248")
.Add(() => incidentDeviceAlias.ClueCd != "258")
.Add(() => incidentDeviceAlias.ClueCd != "975")
.SetResultTransformer(Transformers.AliasToBean<Dto>())
.List<Dto>();
Lambda基準拡張を使用していることに注意してください。または、追加のDtoを作成して、集計関数のないすべての列を選択し、Linqを使用してカウント/合計/最大/カウントを区別できると思います。