I have the following aggregation request:
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>());
Since to calculate the average time it is required to call the datiff function for recording, I use SqlProjection
private static AggregateProjection CountAverageCompletionTimeForTasksCriteria() { return Projections.Avg(Projections .SqlProjection("datediff(ss, Created, CompletedDate) as CompletionTimeInSeconds", new[] {"CompletionTimeInSeconds"}, new[] {NHibernateUtil.Double})); }
The problem is that both Task and TaskChain have the same names for the Created and CompletedDate properties, so I need to pass an alias. But I can not get the string alias to form the correct sql projection. Is there a way to get these aliases, or can I insert in a function dated in the request in another way?
source share