4
我的下一個聚集查詢:QueryOver找到別名串
IQueryOver<CustomerTask, CustomerTask> query = GetSession().QueryOver(() => task)
.JoinAlias(() => task.TaskList,() => taskList)
.JoinAlias(() => task.TaskChain,() => taskChain)
.Where(() => taskList.SalesFlow == salesFlow)
.Select(
Projections.Group(() => taskList.Id)
.WithAlias(() => salesFlowTaskStatisticsGridRow.RowId),
Projections.Group(() => taskList.SalesFlow.Id)
.WithAlias(() => salesFlowTaskStatisticsGridRow.SalesFlowId),
Projections.Group(() => taskList.Name).WithAlias(() => salesFlowTaskStatisticsGridRow.Name),
// ReSharper disable ExpressionIsAlwaysNull
criteriaBuilder.FindAverageCompletionTime(salesFlowTaskStatisticsGridRow)
// ReSharper restore ExpressionIsAlwaysNull
).TransformUsing(Transformers.AliasToBean<SalesFlowTaskStatisticsGridRow>());
由於計算的平均時間需要調用DATEDIFF函數寫它,我用SqlProjection
private static AggregateProjection CountAverageCompletionTimeForTasksCriteria()
{
return Projections.Avg(Projections
.SqlProjection("datediff(ss, Created, CompletedDate) as CompletionTimeInSeconds",
new[] {"CompletionTimeInSeconds"}, new[] {NHibernateUtil.Double}));
}
的問題是,無論是任務 and TaskChain與創建的和完成日期屬性,所以我需要傳遞一個別名。但我無法設法得到字符串別名來形成正確的sql投影。有沒有辦法得到這些別名,或者我可以堅持在功能到查詢以其他方式嗎?