EntityFramework sum嵌套
一个查询中 用到了 sum , 可是返回结果的小数有很多位 , 都不准确了..类似js中的小数运算一样...不太熟悉C#,不知道这问题是因为double的关系 , 还是因为代码写的问题 ,
通过 sql server profile 获取的sql语句执行后都是没有问题的
这是我的代码:
var query = db.SupDataGreenAccount1
.Where(lambda)
.GroupBy( p => new{
p.ObjPos , p.District , p.Feature
})
.Select(
p => new {
//area是 double , 数据库中是 float
sums = p.Sum(c => (double?)c.Area ?? 0),
objpos = p.Key.ObjPos ,
district = p.Key.District ,
feature = p.Key.Feature
}); var ss = query.ToArray(); var list = query.ToList();
这是调试中获取的数据:

这是 sql server profile 执行的sql:

SELECT
1 AS [C1],
[GroupBy1].[A1] AS [C2],
[GroupBy1].[K1] AS [ObjPos],
[GroupBy1].[K3] AS [DISTRICT],
[GroupBy1].[K2] AS [FEATURE]
FROM ( SELECT
[Extent1].[ObjPos] AS [K1],
[Extent1].[FEATURE] AS [K2],
[Extent1].[DISTRICT] AS [K3],
SUM([Extent1].[AREA]) AS [A1]
FROM [dbo].[Sup_Data_GreenAccount_1] AS [Extent1]
WHERE (1 = 1) AND (( CAST(CHARINDEX([Extent1].[DISTRICT], N'保税区') AS int)) > 0)
GROUP BY [Extent1].[ObjPos], [Extent1].[FEATURE], [Extent1].[DISTRICT]
) AS [GroupBy1]

这是执行上面的SQL返回的结果:

EntityFramework sum嵌套的更多相关文章
- [LeetCode] Nested List Weight Sum 嵌套链表权重和
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- [leetcode]339. Nested List Weight Sum嵌套列表加权和
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- [leetcode]364. Nested List Weight Sum II嵌套列表加权和II
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- 【leetcode】339. Nested List Weight Sum
原题 Given a nested list of integers, return the sum of all integers in the list weighted by their dep ...
- python基础3、4---流程控制、运算符
1.for循环 和while循环 for 临时变量 in 待遍历的数据: 循环体 (循环体这里一般加break,结束循环,执行else代码) else: 循环不满足条件执行的代码 while 表达式 ...
- LinkedIn TAG
List1 [leetcode]243. Shortest Word Distance最短单词距离 Two Pointers [leetcode]244. Shortest ...
- LeetCode 339. Nested List Weight Sum (嵌套列表重和)$
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- [Swift]LeetCode339. 嵌套链表权重和 $ Nested List Weight Sum
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- 【原创】从 列表的重复 到 用sum展开二层嵌套列表将子元素合并
转载请注明出处:https://www.cnblogs.com/oceanicstar/p/9517159.html ★像R语言里头有rep函数可以让向量的值重复,在python里面可以直 ...
随机推荐
- Android----------eclipse常用快捷键
类级操作:--------------------一个去包,一个导包------------------------------------ Ctrl+shift+O (不是零) 清除没用引用 ctr ...
- PHP学习笔记二十三【This】
<?php Class Person { function test1() { $this->test2();//类里面的方法互相调用要加$this } protected functio ...
- UVA 227 Puzzle - 输入输出
题目: acm.hust.edu.cn/vjudge/roblem/viewProblem.action?id=19191 这道题本身难度不大,但输入输出时需要特别小心,一不留神就会出问题. 对于输入 ...
- jQuery模板插件jsrender
前几天学习jqm+phonegap,用到了一个jquery插件jsrender,(由于app不能用asp.net的服务端控件了,所以我也是醉了...),用于循环展示一下数据. 下面是我用到的几个简单用 ...
- PK投票效果
/** *createTime:2015-07-21 *updateTime:2015-06-22 *author:刘俊 *Description:PK投票 *phone:13469119119 ** ...
- DOM2定位与高宽类属性专题学习【DOM专题学习系列(一)】
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- Android SqLite升级
android开发中,如果大家使用到了sqlite就会牵涉到它的升级问题,因为升级后的表结构可能完全不一样,会有字段的添加或者删除等.. sqlite升级思路: 1:将表A重新命名:例 ...
- java 数字补齐0
String str_f = str.substring(0, 1); int i = (Integer.parseInt(str.substring(1)) + 1); // 数字补齐0 Decim ...
- Laravel 实现 Facades 功能
使用过Laravel的同学都知道Facades 的强大,下面就让我们一起创建一个Facades 实例.如有不正确的地方,还请不吝赐教. 1. 实现Laravel的自动加载功能 首先建立目录app/li ...
- Linux系统编程(1)——文件与I/O之C标准I/O函数与系统调用I/O
Linux系统的I/O也就是一般所说的低级I/O--操作系统提供的基本IO服务,与os绑定,特定于Linux平台.而标准I/O是ANSI C建立的一个标准I/O模型,是一个标准函数包和stdio.h头 ...