Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Sorting problem with Linq

Sorting problem with Linq

Scheduled Pinned Locked Moved LINQ
databasecsharpsql-serverlinqsysadmin
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr programboy
    wrote on last edited by
    #1

    I have the following code : DataClassesDataContext dc = new DataClassesDataContext(); IOrderedQueryable myObject; public IOrderedQueryable ZoekDossier(string pDossierNr, string pKlantNaam, string pDeurwNaam, string pOpdrNaam, Int32 pSector, string pSortColumn) { if (string.IsNullOrEmpty(pDossierNr) & !string.IsNullOrEmpty(pKlantNaam) & string.IsNullOrEmpty (pDeurwNaam) & string.IsNullOrEmpty(pOpdrNaam)) { switch (pSortColumn) { case "Dossiernr": var myRecordSetDosNr = from invordering in dc.Invorderings join invo_klan in dc.Invordering_Klants on invordering.INVO_ID equals invo_klan.INKL_INVO_ID join klant in dc.Klants on invo_klan.INKL_KLAN_ID equals klant.KLAN_ID where klant.KLAN_NM.StartsWith(pKlantNaam) & invordering.INVO_SECT_ID == pSector select new { Dossiernr = invordering.INVO_DOS_NR, Hoofdschuld = invordering.INVO_BDR_HFD, Intrest = invordering.INVO_BDR_INT, Kosten = invordering.INVO_BDR_KOS, Klantnaam = klant.KLAN_NM }; myObject = myRecordSetDosNr.OrderBy(p => p.Dossiernr); break; ... When I bind this to a GridView the sorting is done but not in a correct way... The result is : 4, 10, 8, 12, ... So it doesn't sort the right ascending way. Anyone has an idea ? Dossiernr is a varchar(50) field in de SQL Server 2005 database Thx

    F 1 Reply Last reply
    0
    • M Mr programboy

      I have the following code : DataClassesDataContext dc = new DataClassesDataContext(); IOrderedQueryable myObject; public IOrderedQueryable ZoekDossier(string pDossierNr, string pKlantNaam, string pDeurwNaam, string pOpdrNaam, Int32 pSector, string pSortColumn) { if (string.IsNullOrEmpty(pDossierNr) & !string.IsNullOrEmpty(pKlantNaam) & string.IsNullOrEmpty (pDeurwNaam) & string.IsNullOrEmpty(pOpdrNaam)) { switch (pSortColumn) { case "Dossiernr": var myRecordSetDosNr = from invordering in dc.Invorderings join invo_klan in dc.Invordering_Klants on invordering.INVO_ID equals invo_klan.INKL_INVO_ID join klant in dc.Klants on invo_klan.INKL_KLAN_ID equals klant.KLAN_ID where klant.KLAN_NM.StartsWith(pKlantNaam) & invordering.INVO_SECT_ID == pSector select new { Dossiernr = invordering.INVO_DOS_NR, Hoofdschuld = invordering.INVO_BDR_HFD, Intrest = invordering.INVO_BDR_INT, Kosten = invordering.INVO_BDR_KOS, Klantnaam = klant.KLAN_NM }; myObject = myRecordSetDosNr.OrderBy(p => p.Dossiernr); break; ... When I bind this to a GridView the sorting is done but not in a correct way... The result is : 4, 10, 8, 12, ... So it doesn't sort the right ascending way. Anyone has an idea ? Dossiernr is a varchar(50) field in de SQL Server 2005 database Thx

      F Offline
      F Offline
      Furty
      wrote on last edited by
      #2

      Group By and Order By[^]

      M 1 Reply Last reply
      0
      • F Furty

        Group By and Order By[^]

        M Offline
        M Offline
        Mr programboy
        wrote on last edited by
        #3

        No that was too easy :p I wanted to use "late binding" for the "order by" clause and I solved this with the LINQ Dynamic Query Library. You can find the link here : http://aspalliance.com/1569\_Dynamic\_LINQ\_Part\_1\_Using\_the\_LINQ\_Dynamic\_Query\_Library.3 Just add the "Dynamic.cs" class to your data/business layer en build it. Then it is possible to use the OrderBy method where you can pass a string value.

        F 1 Reply Last reply
        0
        • M Mr programboy

          No that was too easy :p I wanted to use "late binding" for the "order by" clause and I solved this with the LINQ Dynamic Query Library. You can find the link here : http://aspalliance.com/1569\_Dynamic\_LINQ\_Part\_1\_Using\_the\_LINQ\_Dynamic\_Query\_Library.3 Just add the "Dynamic.cs" class to your data/business layer en build it. Then it is possible to use the OrderBy method where you can pass a string value.

          F Offline
          F Offline
          Furty
          wrote on last edited by
          #4

          Mr programboy wrote:

          I wanted to use "late binding" for the "order by" clause

          If the list is going to be data-bound in a WinForms UI, another option would be a SortableBindingList like the one illustrated here[^] - this has the added benefit of automatically giving the end-user re-sort capabilities at runtime without you touching a further line of code..

          M 1 Reply Last reply
          0
          • F Furty

            Mr programboy wrote:

            I wanted to use "late binding" for the "order by" clause

            If the list is going to be data-bound in a WinForms UI, another option would be a SortableBindingList like the one illustrated here[^] - this has the added benefit of automatically giving the end-user re-sort capabilities at runtime without you touching a further line of code..

            M Offline
            M Offline
            Mr programboy
            wrote on last edited by
            #5

            I'm not using a WinForm but thanks :-) This topic can be closed.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups