none
SQL to LINQ help needed RRS feed

  • Question

  • I need help in converting the folowwing SQL query to Linq, can someone help in this.

     

     

    select TOP (1) resultStatus, COUNT(resultstatus) as 'countStatus' from 
    
    (
    
    //I have List<> here
    
    )
    
    group by resultStatus
    order by countStatus DESC
    

     


    Muhammad Umair Irshad http://www.umair.me

    Sunday, March 27, 2011 3:17 PM

Answers

  • Well i got it working now, for those who need any help regarding this query it is working for me perfect:

     

          var q = (from ab in lstDeviceLatest
               group ab by new
               {
                 ab.resultStatus
               } into g
               orderby
                (Int64?)g.Count() descending
    
               select new
               {
                 resultStatus = (System.Int32?)g.Key.resultStatus,
                 countStatus = (Int64?)g.Count()
               }).Take(1);
    

    Mark as answer if it helps you.


    Muhammad Umair Irshad http://www.umair.me
    • Marked as answer by Umair ME Monday, March 28, 2011 11:10 PM
    Monday, March 28, 2011 11:10 PM

All replies

  • Well i got it working now, for those who need any help regarding this query it is working for me perfect:

     

          var q = (from ab in lstDeviceLatest
               group ab by new
               {
                 ab.resultStatus
               } into g
               orderby
                (Int64?)g.Count() descending
    
               select new
               {
                 resultStatus = (System.Int32?)g.Key.resultStatus,
                 countStatus = (Int64?)g.Count()
               }).Take(1);
    

    Mark as answer if it helps you.


    Muhammad Umair Irshad http://www.umair.me
    • Marked as answer by Umair ME Monday, March 28, 2011 11:10 PM
    Monday, March 28, 2011 11:10 PM
  • Happy to see that Muhammad,and thank you very much for sharing your solution to us! This will be helpful!

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 30, 2011 3:35 AM
    Moderator