0
這是我的SQL查詢我想SQL查詢轉換爲LINQ查詢
SELECT a.CLASS_ID,a.ACTIVITY_TYPE_ID,COUNT(*)
FROM AIS.CLASS_ASSESSMENT_DATE_INFO a
WHERE a.CLASS_ID =22222
GROUP by a.CLASS_ID,a.ACTIVITY_TYPE_ID
我想這個查詢LINQ查詢轉換。你可以幫我嗎 ?
這是我的SQL查詢我想SQL查詢轉換爲LINQ查詢
SELECT a.CLASS_ID,a.ACTIVITY_TYPE_ID,COUNT(*)
FROM AIS.CLASS_ASSESSMENT_DATE_INFO a
WHERE a.CLASS_ID =22222
GROUP by a.CLASS_ID,a.ACTIVITY_TYPE_ID
我想這個查詢LINQ查詢轉換。你可以幫我嗎 ?
試試這個: -
var result = db.CLASS_ASSESSMENT_DATE_INFO.Where(x => x.CLASS_ID == 22222)
.GroupBy(x => new { x.CLASS_ID, x.ACTIVITY_TYPE_ID })
.Select(x => new
{
CLASS_ID = x.Key.CLASS_ID,
ACTIVITY_TYPE_ID = x.Key.ACTIVITY_TYPE_ID,
Count = x.Count()
});
或在情況下,如果你喜歡query syntax
: -
var result = from x in db.CLASS_ASSESSMENT_DATE_INFO
where x.CLASS_ID == 22222
group x by new { x.CLASS_ID, x.ACTIVITY_TYPE_ID } into g
select new
{
CLASS_ID = g.Key.CLASS_ID,
ACTIVITY_TYPE_ID = g.Key.ACTIVITY_TYPE_ID,
Count = g.Count()
};
var q = from a in AIS.CLASS_ASSESSMENT_DATE_INFO
where a.CLASS_ID == 22222
group a by new{
a.CLASS_ID,
a.ACTIVITY_TYPE_ID} into g
select new{
CLASS_ID = g.Key.CLASS_ID,
ACTIVITY_TYPE_ID = g.Key.ACTIVITY_TYPE_ID,
Count = g.Count()
};