需要使用 query Over (Nhibernate) C# 创建一个查询,以添加多个列。纯 sql 示例:
SELECT SUM(col1 + col2 + col3 + col4)
FROM tabela
首先我是这样制作的:
Table table = null;
Session.QueryOver<Table>(() => tabela)
.Select(Projections.Sum<Table>(t => t.col1))
.Select(Projections.Sum<Table>(t => t.col2))
.Select(Projections.Sum<Table>(t => t.col3))
.Select(Projections.Sum<Table>(t => t.col4))
但是这样每列又生成4列,会全部相加只生成一列。
最佳答案
它更简单:
Table table = null;
Session.QueryOver<Table>(() => tabela)
.Select(Projections.Sum<Table>(t => t.col1 + t.col2 + t.col3 + t.col4))
关于c# - 在 Nhibernate 中创建查询 "sum"多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38222948/