The following command returns the expected output in SQL Server :
select count(*) As CountField
from
(select Eductionals.UserID , Max(Eductionals.MaghtaeID) As IDmaghta
from Eductionals
group by Eductionals.UserID) Temptable
inner join MaghtaeTahsilis ON
Temptable.IDmaghta = MaghtaeTahsilis.ID
where Temptable.IDmaghta = 3 /* any number */
group by Temptable.IDmaghta
I tried to convert the above code to LINQ :
var maghtae = _maghtaeTahsili.Where(z => z.Code == MaghtaeCode).FirstOrDefault();
return _eductional.GroupBy(z=> z.UserID).Max().Where(z => z.MaghtaeID == maghtae.ID).Select(z => z).Count();
After running, I encounter the following error:
'IGrouping' does not contain a definition for 'MaghtaeID' and no accessible extension method 'MaghtaeID' accepting a first argument of type 'IGrouping' could be found (are you missing a using directive or an assembly reference?)