Linq query's sorted properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vivien Parlat

    Linq query's sorted properties

    Hello,

    I am currently using VB.Net 2008 express. I use linq to perform
    queries on a database, and I'm using the following link's source to
    convert those queries into DataTables i can then bind to WinForms'
    DataGridViews:



    The point is, the properties names extracted by the following lines:
    _type = GetType(T)
    _pi = _type.GetProper ties()
    .... are sorted alphabetically !
    I cannot figure out how to keep them "unsorted", ie sorted as they are
    in my Select clause.

    Can anyone help me ?

    Thanks a lot in advance...
  • Lloyd Sheen

    #2
    Re: Linq query's sorted properties

    Vivien Parlat wrote:
    Hello,
    >
    I am currently using VB.Net 2008 express. I use linq to perform
    queries on a database, and I'm using the following link's source to
    convert those queries into DataTables i can then bind to WinForms'
    DataGridViews:
    >

    >
    The point is, the properties names extracted by the following lines:
    _type = GetType(T)
    _pi = _type.GetProper ties()
    ... are sorted alphabetically !
    I cannot figure out how to keep them "unsorted", ie sorted as they are
    in my Select clause.
    >
    Can anyone help me ?
    >
    Thanks a lot in advance...
    Vivien,

    First question is why are you using DataTables when you can bind using
    the objects created in the Linq query. If you set up your DataGridView
    with columns and set the DataPropertyNam e then binding the data will
    show the data from your query correctly.

    LS

    Comment

    • Vivien Parlat

      #3
      Re: Linq query's sorted properties

      On 20 août, 20:44, Lloyd Sheen <a...@b.cwrot e:
      Vivien Parlat wrote:
      Hello,
      >
      I am currently using VB.Net 2008 express. I use linq to perform
      queries on a database, and I'm using the following link's source to
      convert those queries into DataTables i can then bind to WinForms'
      DataGridViews:
      >>
      The point is, the properties names extracted by the following lines:
          _type = GetType(T)
          _pi = _type.GetProper ties()
      ... are sorted alphabetically !
      I cannot figure out how to keep them "unsorted", ie sorted as they are
      in my Select clause.
      >
      Can anyone help me ?
      >
      Thanks a lot in advance...
      >
      Vivien,
      >
      First question is why are you using DataTables when you can bind using
      the objects created in the Linq query.  If you set up your DataGridView
      with columns and set the DataPropertyNam e then binding the data will
      show the data from your query correctly.
      >
      LS
      I'm using Datatables because I'm trying to modify someone's code, and
      the previous developers have isolated all linq queries in a single
      dll, each one having its own Function returning a DataTable, and each
      one ending with a call to CopyToDataTable or to previously quoted
      ToDataTable method.
      As far as (I (believe) I know, anonymous type cannot be used in
      parameters or return values, so I could not find out good and simple
      replacement method. Maybe I am wrong, which could help me much :)

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Linq query's sorted properties

        Vivien,
        Have you tried your code under VS2008 SP1 (.NET 3.5 SP1).

        There's a bug in VS 2008 (.NET 3.5) that causes an anonymous type's
        properties to be sorted. I tried a quick sample under VS 2008 SP1 (.NET 3.5
        SP1) and it appears the bug has been fixed.


        --
        Hope this helps
        Jay B. Harlow
        ..NET Application Architect, Enthusiast, & Evangelist
        T.S. Bradley - http://www.tsbradley.net


        "Vivien Parlat" <pocky6@gmail.c omwrote in message
        news:4e10fbea-c95d-4502-8982-91d6b56662a7@i7 6g2000hsf.googl egroups.com...
        On 20 août, 20:44, Lloyd Sheen <a...@b.cwrot e:
        Vivien Parlat wrote:
        Hello,
        >
        I am currently using VB.Net 2008 express. I use linq to perform
        queries on a database, and I'm using the following link's source to
        convert those queries into DataTables i can then bind to WinForms'
        DataGridViews:
        >>
        The point is, the properties names extracted by the following lines:
        _type = GetType(T)
        _pi = _type.GetProper ties()
        ... are sorted alphabetically !
        I cannot figure out how to keep them "unsorted", ie sorted as they are
        in my Select clause.
        >
        Can anyone help me ?
        >
        Thanks a lot in advance...
        >
        Vivien,
        >
        First question is why are you using DataTables when you can bind using
        the objects created in the Linq query. If you set up your DataGridView
        with columns and set the DataPropertyNam e then binding the data will
        show the data from your query correctly.
        >
        LS
        I'm using Datatables because I'm trying to modify someone's code, and
        the previous developers have isolated all linq queries in a single
        dll, each one having its own Function returning a DataTable, and each
        one ending with a call to CopyToDataTable or to previously quoted
        ToDataTable method.
        As far as (I (believe) I know, anonymous type cannot be used in
        parameters or return values, so I could not find out good and simple
        replacement method. Maybe I am wrong, which could help me much :)

        Comment

        Working...