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里面可以直 ...
随机推荐
- Repeater控件的详细用法
中隔行(交替项)呈现一次.通过设置 AlternatingItemTemplate 元素的样式属性,可以为其指定不同的外观. FooterTemplate在所有数据绑定行呈现之后呈现一次的元素.典型的 ...
- 插头DP题目泛做(为了对应WYD的课件)
题目1:BZOJ 1814 URAL 1519 Formula 1 题目大意:给定一个N*M的棋盘,上面有障碍格子.求一个经过所有非障碍格子形成的回路的数量. 插头DP入门题.记录连通分量. #inc ...
- hdu3599 War(最大流)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud War Time Limit: 2000/1000 MS (Java/Others ...
- 初学linux命令
linux系统的精髓在于它的命令行 早就听说要学习linux系统,就要学习它的命令行(Command Line Interface).说来惭愧,已经使用了linuxmint快两个月了,虽然能够使用一些 ...
- Ultra-QuickSort(树状数组+离散化)
Ultra-QuickSort POJ 2299 Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 50495 Accep ...
- [转]从数据库中导出用友U8的现存量数据到Excel表
转载自:http://www.czerp.com.cn/page/Default.asp?ID=372 可通过Excel获取外部数据的方式与SQL数据库创建查询连接,并导入到Excel中: Selec ...
- ini_set()注意要点和解决方法
在php编程中,很多情况下,我们不希望通过修改配置文件(php.ini)来实现相关功能,这样不利于代码的可移植性. 大多数情况下,我们会使用ini_set()来实现配置文件的占时修改.但需要注意的是, ...
- css案例学习之div ul li a 实现导航效果
效果 代码 <html> <head> <title>无需表格的菜单</title> <style> body{ background-co ...
- PV与并发之间换算的算法 换算公式
- svn add后的数据如何取消-svn revert??--zz
svn add后的数据如何取消-svn revert?? 有时候你发现svn add后,这个提交的数据又不需要了.这时候需要有svn revert来处理了. 原文链接:http://hi.baidu. ...