分组依据不包括"null"数据



我正在尝试计算状态统计信息,但问题是当我分组时,我没有得到"null"统计信息。

Parent:
Id   Status
1    Processed
2    Hold
3    Review
4    Closed
5    Rejected
6    Draft
Child :
Id    UserId    ParentId
1     100       1
2     100       1
3     100       1
4     100       1
5     100       2
6     100       2
7     100       2
8     100       3
4     100       3
8     100       4
4     100       4
9     100       5
10    100       6
11    100       null
12    100       null

预期输出:

Processed = 4
Hold = 3
Review = 2
Closed = 2
Rejected = 1
Draft = 1
Null = 2

查询:

var data = (from c in context.Child
where c.UserId == 100 &&
(c.Parent ==null || c.Parent.IsActive)
group c by new
{
c.ParentId,
c.Parent.Status
} into g
select new StatusWiseStatsResult
{
Status = g.Key.Status,
Statistics = g.Count(),
Id = g.Key.ParentId == null ? 0 : (int)g.Key.ParentId
}).OrderByDescending(c => c.Statistics).ToList();

但它并没有返回";空";上述查询中的计数为2。

有人能告诉我问题出在哪里吗?

点击此处查看这一行

(c.Parent ==null || c.Parent.IsActive)

把它拿出来。然后检查c.Parent.IsActive!=错误

.Where(x => c.Parent != null ? c.Parent.IsActive : true)

最新更新