我在使用 Entity SQL 计算空值时遇到问题。
SQL中的代码:
SELECT Table.City, COUNT(*)
FROM Table
GROUP BY Table.City
在 Linq to Entity 中:
var query1 = from g in context.Table
group g by g.City into mygroup
select new { mygroup, c = mygroup.Count() };
两者都返回正确的值:
NULL 4
Boston 7
Canberra 1
London 5
Melbourne 5
New York 4
Paris 15
Sydney 4
但是,Entity SQL 代码编写如下:
string queryString1 = "SELECT city, COUNT(g.City)" +
"FROM Entities.Table AS g " +
"GROUP BY g.City as city";
返回:
NULL 0
Boston 7
Canberra 1
London 5
Melbourne 5
New York 4
Paris 15
Sydney 4
为什么 NULL 没有正确计算?我该如何解决?