none
Sorting on expression in LINQ RRS feed

  • Question

  • Hi

    How can a query be sorted by year and month parts of a datetime field in LINQ?

    Basically I am looking for LINQ equivalent of the following SQL;

    SELECT <colList>
    FROM <MyTable>
    Order By Year(<dateCol>), MONTH(<dateCol>)

    Thanks

    Regards


    Saturday, July 23, 2011 6:22 PM

Answers

  • Hi Y a h y a;

    The format of the following Linq to Entity Framework will do what you want.

     

    Dim query = From c In MyTable
       Order By c.dateCol.Year, c.dateCol.Month
       Select <colList>
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Saturday, July 23, 2011 7:00 PM

All replies

  • Hi Y a h y a;

    The format of the following Linq to Entity Framework will do what you want.

     

    Dim query = From c In MyTable
       Order By c.dateCol.Year, c.dateCol.Month
       Select <colList>
    

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Saturday, July 23, 2011 7:00 PM
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[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.

    Tuesday, August 2, 2011 3:56 PM
    Moderator