C# 查询查找别名字符串
我有下一个聚合查询:C# 查询查找别名字符串,c#,sql-server,nhibernate,fluent-nhibernate,C#,Sql Server,Nhibernate,Fluent Nhibernate,我有下一个聚合查询: IQueryOver<CustomerTask, CustomerTask> query = GetSession().QueryOver(() => task) .JoinAlias(() => task.TaskList, () => taskList) .JoinAlias(() => task.TaskChain, () => taskChain) .Where(() => taskLis
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>());
问题是任务和任务链对于创建的和完成日期属性具有相同的名称,因此我需要传递一个别名。但是我无法获得字符串别名以形成正确的sql投影。有没有办法获取这些别名,或者我可以通过其他方式将datediff函数插入查询?NHibernate在使用SqlProjection时没有提供很多复杂的选项来处理别名 唯一的解决方法是首先在不使用datediff投影的情况下分析查询,然后查看NHibernate在任务和任务链中使用的别名(它们可能类似于此和*此\ 1*)。然后可以手动将这些别名硬编码到投影中,如下所示:
.SqlProjection("datediff(ss, this_.Created, this_.CompletedDate) as CompletionTimeInSeconds",
new[] {"CompletionTimeInSeconds"}, new[] {NHibernateUtil.Double})
显然,这远不是完美的,但它会起作用
.SqlProjection("datediff(ss, this_.Created, this_.CompletedDate) as CompletionTimeInSeconds",
new[] {"CompletionTimeInSeconds"}, new[] {NHibernateUtil.Double})