如何设置在动态linq查询中使用的聚合函数的结果的一轮? [英] How to set round of the result of aggregate function used in dynamic linq query?

查看:173
本文介绍了如何设置在动态linq查询中使用的聚合函数的结果的一轮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码:

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位十进制数字。如何在这个查询中添加它?

I wish to round of the result of Sum() method above to 2 decimal digits. How can I add it in this query itself?

推荐答案

不知何故,动态linq并不总是能够理解他们的数字,所以尝试这样:

Somehow dynamic linq does not always understand the numbers in terms of their, so try this:

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);

这篇关于如何设置在动态linq查询中使用的聚合函数的结果的一轮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆