Ask a questionAsk a question
 

QuestionLinq Equivalent of Row_Number() over (partition by )

  • Monday, October 26, 2009 10:16 AMMadhanlal JM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    What is the Linq Equivalent of

    Select Row_Number() over (partition by field1, field2) as Rank (sql server 2005)

    or

    How can we achieve Ranking and partition  using Linq Statements

    Regards
    Madhanlal JM
     

All Replies

  • Wednesday, October 28, 2009 5:12 AMYichun_FengMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Madhanlal,

     

    There is similar thread discussing about this issue,

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/055911ff-6db6-48cb-8e50-bd6415b7eefe/

     

    As the MSFT mentioned, it is not supported in LINQ to Entity. You can load the records into memory to achieve it.

     

     

    If you have any questions or concerns, please provide more details about your issue and we will have a further discussion.

     

     

    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Friday, October 30, 2009 6:50 AMMadhanlal JM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Yichun_Feng
     
       Sorry for the delayed reply.


    I have following record in emp table
        
    Id      EmpId    BranchId     Description
    1         2            4                   quick brown             
    2         1            2                   quic
    3         2            4                   quick
    4         1            2                   qui
        
        
    I want to display it in the Below format.

    Id      EmpId    BranchId     Description
    4        1             2                   qui
    2        1             2                   quic
    3        2             4                   quick
    1        2             4                   quick brown             


    I am using GroupBy for the desired result. But it needs
    more iteration logic to rearrange.

    Any other way? or
    linq query to achieve this?

    Regards
    Madhanlal JM
  • Wednesday, November 04, 2009 5:58 PMNoam Ben-Ami - MSFTMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    What exactly is desired here? It looks like you are just sorting by string length here?
    This posting is provided "AS IS" with no warranties, and confers no rights.