0

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?)

hian cuei
  • 35
  • 8
  • You are using Max() which returns a singleton and the Where need a list object. – jdweng Feb 11 '19 at 17:01
  • 1
    Perhaps my [SQL to LINQ Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) would help you. – NetMage Feb 11 '19 at 18:29

0 Answers0