Home General
Options

Sorting result table columns

Is there a way to control the display order of columns in a result table?

I would like to sort them alphabetically to make it easier to find a specific column in a result table.

Thanks.

Comments

  • If you click 'Results to Data Grids' or click the extenser arrow on the table and do the same, you'll get headers that you can click to sort.
  • Thanks for the response. I see I can sort the rows by column. However I was interested in knowing if I can change the display order of the columns themselves.

    For example lets say there are four columns in the table.

    StudentId, Grade, Subject, Book

    Can I make the columns instead be

    Book, Grade, StudentId, Subject.

    Currently it looks like the columns are displayed in the order they were added to the table with relationships at the end.

    If a table has a lot of columns it is difficult to locate specific columns. I know I could create a specific Select statement to only retrieve specific columns but was wondering if there was another way.
  • edited October 2014
    So you want an option for alphabetical ordering on a per-query basis? Or globally?
  • I think having an option in the results window (for example in the lefthand side option menu) that was "sort columns alphabetically" or something would be the most flexible. That way if someone was to make a Select with a specific order that would also be preserved.
  • Did anything every happen with this? I have the same issue, and it's very frustrating trying to find columns.

    Alphabetical would be fine. Even better would be to use the order in which the properties are defined in the model, although I realise that this might not be possible.

  • If it's a LINQ-to-SQL or EF Core model that LINQPad builds, the default ordering is based on the column order in the database. You can change this to alphabetical using the checkbox in the connection dialog.

    If it's an EF Core model from a custom assembly, it uses the order that you defined the properties in.

    In both cases, you can also force alphabetical ordering for all results in Settings. Go to Edit | Preferences > Results, or in LINQPad 9, Settings > Results.

    Does this answer you question?

  • Hello Joe,

    Thanks for the reply. It helps, in that I can see them alphabetically, which certainly makes it easier. However, I'm confused when you say the default ordering is based on the column order in the database. I can see the column order in my database, and it's nothing like the order I get when I choose "Ordinal" for the sorting in LinqPad.

    Any ideas? Thanks again.

  • What kind of connection is it?

  • What's the provider, and did LINQPad build the model, or is it from a custom assembly?

    If LINQPad built the model, and it's SQL Server, try running the following SQL:

    create table ColOrderTest (ID int not null primary key, Col9 int, Col8 int, Col7 int, Col6 int, Col5 int, Col4 int, Col3 int, Col2 int, Col1 int)
    

    Does this table appear in the defined column order?

  • Could this not be solved by using a ToDump extension? Sure, it's not automatic, but it is explicit.

  • Yes, that's a good point. But the defaults should still work as expected. If the columns are being displayed in a completely random order, it would be good to diagnose and fix the bug.

  • @JoeAlbahari The provider is SQL Server, and the model is in an ASP.NET Core Blazor web app assembly.

  • So you built the model yourself in Visual Studio? Is there any relation to the order in which the properties are defined in the .cs file in your model and the order that they appear in LINQPad?

  • @JoeAlbahari Well, I didn't build the model, I created the .cs files and VS build the assembly, but I guess that's what you meant!

    No, the ordering is completely different. I was initially hoping that LinqPad would show them in the order they were in the .cs file, as that generally makes sense to me, but I haven't found any pattern to the order used.

    Thanks again

  • In what order are the columns returned when you run the following script:

    Model.GetEntityTypes().Single (t => t.ClrType == typeof (MyTable)).GetProperties ().Select (p => new { p.Name, Type = p.ClrType.Name  })
    

    where MyTable is your table type?

  • They are in alphabetical order with your query.

  • There's something very strange going on. For now, I've added an option to the EF Core connection dialog in LINQPad 9 to put the columns in alphabetical order.

Sign In or Register to comment.