我有一个名为的表IssueStatuses
和另一个名为 Issues 的表。问题有 aStatusID
和SubStatusID
,两者都来自IssueStatuses
表,该表有一个附加字段,说明它是否是 a SubStatus
,如下所示:
问题状态
- 问题状态ID
- 问题状态
- 是子状态
我正在尝试获取SubStatuses
特定问题列表的列表。在 SQL 中是:
SELECT iss.IssueStatus, COUNT(iss.IssueStatus) AS Total
FROM Issues AS Issues
INNER JOIN Rooms r ON Issues.RoomID = r.RoomID
INNER JOIN Locations l ON l.LocationID = r.LocationID
INNER JOIN Customers c ON l.CustomerID = c.CustomerID
INNER JOIN (SELECT * FROM IssueStatuses WHERE IsSubStatus = 0) ist ON Issues.IssueStatusID = ist.IssueStatusID
INNER JOIN (SELECT * FROM IssueStatuses WHERE IsSubStatus = 1) iss ON Issues.IssueSubStatusID = iss.IssueStatusID
WHERE c.Customer = 'ABC'
AND l.Location = 'MySite'
GROUP BY iss.IssueStatus
但我在将其转换为 LINQ 时遇到问题。所需的输出类似于:
问题状态 | 全部的 ------------------ 打开 15 延迟 25 准时 8
这是我用 LINQ 尝试过的:
var query = from i in Issues
join r in Rooms on i.RoomID equals r.RoomID
join l in Locations on r.RoomID equals l.LocationID
join c in Customers on l.CustomerID equals c.CustomerID
where i.IssueStatusID == (from ist in IssueStatuses
where ist.IsSubStatus == false
select ist)
&& i.IssueSubStatusID == (from iss in IssueStatuses
where iss.IsSubStatus == true
select iss)
&& c.Custome == "ABC"
&& l.Location == "MySite"
group i by i.IssueStatus
但我知道这是错误的,因为LINQPad
会引发错误说明:
can't convert int to type Models.IssueStatus
我需要做的是用于iss.IssueStaus
分组,但我无法访问它。有人可以告诉我我做错了什么吗?