none
Entity Framework Sort Order in Data Grid RRS feed

  • Question

  • I am using a basic Entity Framework Model which is Tied to SQL Server View. Where do I find the statement which needs to be modified to include the

    Order by clause, so I can change the default sort order of my datagrid?

    (e.g. Contact.Phones.OrderBy ( @p => @p.SortOrder ) )

    Thank you

    Monday, August 15, 2011 5:29 PM

All replies

  • Hello,

    Please move this question to the EF forum :

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/threads

    Thanks!


    Monica Frintu
    Monday, August 15, 2011 6:18 PM
    Answerer
  • Hi jmcpsd;

    In your example query (e.g. Contact.Phones.OrderBy ( @p => @p.SortOrder ) ) is Phones the column you want to sort the table Contact by?

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, August 15, 2011 7:16 PM
  • yes, I know there is a place to edit the query after it is generated from EF, but I cannot remember where it is located so I can add the Order By Clause.
    Monday, August 15, 2011 7:51 PM
  • OK is this a web application and if it is are you using a EntityDataSource? If so then the EntityDataSource.OrderBy property is where you set the ordering of the query, MS documentation here.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, August 15, 2011 8:02 PM
  • It's actually a Silverlight, and I am using ADO.Net and Domain Service, so I don't think I'm using a EntityDataSource. Does that help ?
    Monday, August 15, 2011 8:57 PM
  • Nop. In your original question you stated the following, "I am using a basic Entity Framework Model which is Tied to SQL Server View", can you show the code.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, August 15, 2011 9:08 PM
  • THank you...

    I found where the change needs to be made:

     

    public

     

    IQueryable<vwPagerApp

    > GetVwPagerApps()

    {

     

    //return this.ObjectContext.vwPagerApps;

     

    return this

    .ObjectContext.vwPagerApps.OrderBy(p => p.Phone);

     

    }

    Tuesday, August 16, 2011 3:54 PM