以下是我的代码:
sFieldList.Select(y => "Sum(Convert.ToDouble(iif(it[\""+y+"\"] == @0,0,it[\""+y+"\"]))) as "+y)and then
var newSort = dataTable
.AsEnumerable()
.AsQueryable()
.GroupBy("new("+gField+")", "it")
.Select("new("+sField+",it.Key as Key, it as Data)",DBNull.Value);
我希望将上面的Sum()方法的结果舍入为2位小数。如何在此查询中添加它?
答案 0 :(得分:0)
希望我能正确理解你的问题,但据我所知,你只需要一个额外的Select()
var roundedSums = list.Select(x => "some dynamic query on x")
.Select(x => Math.Round(x, 2);
通过链接多个Selects(),您只需将原始集投影到记录的基础上。
如果这不是您想要的,我们可能需要更多澄清。
答案 1 :(得分:0)
不知何故,动态linq并不总是理解他们的数字,所以试试这个:
sFieldList.Select(y => "Sum(Math.Round(Convert.ToDouble(iif(it[\""+y+"\"] == @0,0,it[\""+y+"\"])),@1)) as "+y)
然后
var newSort = dataTable
.AsEnumerable()
.AsQueryable()
.GroupBy("new("+gField+")", "it")
.Select("new("+sField+",it.Key as Key, it as Data)",DBNull.Value,2);