문제

I have a query that needs to retrieve 3 fields:

| MaintenanceID | MaintenanceIDCount | StatusID |
|       1       |        2           |    -1    |
|       3       |        2           |    -1    |

The field MaintenanceIDCount (like the name says), is the count of MaintenanceID column.

My basic query expression is above:

var result = from m in Maintenance
     select new
     {
    m.MaintenanceID,
    m.StatusID
     }

The result of this query is:

| MaintenanceID | StatusID |
|       1       |    -1    |
|       1       |    -1    |
|       3       |    -1    |
|       3       |    -1    |

How can I group and mount my query to retrieve a column with the MaintenanceID column count?

Some tips?

도움이 되었습니까?

해결책

from m in Maintenance
group m by new { m.MaintenanceID, m.StatusID } into g
select new {
    g.Key.MaintenanceID,
    g.Key.StatusID,
    MaintenanceIDCount = g.Count()
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top