locked
ObjectQuery Include Orderby RRS feed

  • Question

  •  Hi,

    New to entityframework, from a linq to sql background. Using WPF and drag and drop - a Listbox Master and Grid detail, databinding is fine but need to sort the grid.

    Am able to sort the master data "It.ContactRole in the listbox", but how to get at the detail in the datagrid, the "Common_Contacts" below to sort. I really dont want to create classes/collections at this time.

     Dim Common_Contact_RolesQuery As ObjectQuery(Of DataManagement.Common_Contact_Roles) = DMSCommonEntities.Common_Contact_Roles
            Common_Contact_RolesQuery = Common_Contact_RolesQuery.Include("Common_Contacts")
            Common_Contact_RolesQuery = Common_Contact_RolesQuery.OrderBy("It.ContactRole")

     'Returns an ObjectQuery.
            Return Common_Contact_RolesQuery


        

    Tuesday, April 20, 2010 6:43 AM

Answers

  • Hi Kce,

    The default collections provided by Entity Framework (of type EntityCollection<T>) don't have order. Also, the default binding lists that are returned for them do not support UI control sorting in either WPF or WinForms.

    There is currently no really simple solution for this. One idea is to use your own POCO classes and use a collection type that supports ordering, such as ObservableCollection<T>. The POCO Template (downloadable from here and explained here) generates entity types that are compatible with Entity Framewowork and can use ObservableCollection<T> as a collection type. However, you should disable POCO Proxy creation to actually obtain collections of this type:

    DMSCommon.Entities.ContextOptions.ProxyCreationEnabled = false

    Hope this helps,
    Diego


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by Diego B Vega [MSFT] Friday, April 30, 2010 3:33 AM
    • Marked as answer by Kce Thursday, June 17, 2010 9:44 AM
    Friday, April 30, 2010 3:33 AM

All replies

  •  Hi,

    New to entityframework, from a linq to sql background. Using WPF and drag and drop - a Listbox Master and Grid detail, databinding is fine but need to sort the grid.

    Am able to sort the master data "It.ContactRole in the listbox", but how to get at the detail in the datagrid, the "Common_Contacts" below to sort. I really dont want to create classes/collections at this time.

     Dim Common_Contact_RolesQuery As ObjectQuery(Of DataManagement.Common_Contact_Roles) = DMSCommonEntities.Common_Contact_Roles
            Common_Contact_RolesQuery = Common_Contact_RolesQuery.Include("Common_Contacts")
            Common_Contact_RolesQuery = Common_Contact_RolesQuery.OrderBy("It.ContactRole")

     'Returns an ObjectQuery.
            Return Common_Contact_RolesQuery


        

    Tuesday, April 20, 2010 6:42 AM
  • Hi Kce,

    The default collections provided by Entity Framework (of type EntityCollection<T>) don't have order. Also, the default binding lists that are returned for them do not support UI control sorting in either WPF or WinForms.

    There is currently no really simple solution for this. One idea is to use your own POCO classes and use a collection type that supports ordering, such as ObservableCollection<T>. The POCO Template (downloadable from here and explained here) generates entity types that are compatible with Entity Framewowork and can use ObservableCollection<T> as a collection type. However, you should disable POCO Proxy creation to actually obtain collections of this type:

    DMSCommon.Entities.ContextOptions.ProxyCreationEnabled = false

    Hope this helps,
    Diego


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by Diego B Vega [MSFT] Friday, April 30, 2010 3:33 AM
    • Marked as answer by Kce Thursday, June 17, 2010 9:44 AM
    Friday, April 30, 2010 3:33 AM
  • Thanks Diego,

    So many questions, so much to do, almost forgot about this one

    Thursday, June 17, 2010 9:46 AM