Home

Edit button not available for query that does a Select

Hello, I have LinqPad Premium, and if I do a query e.g. Jobs, then the Edit button appears and I can edit in the data grid. However, if I change the query so that only certain columns come back (because all columns cannot fit on my screen, making editing tedious), e.g. Jobs.Select(j => j.VendorName), then the Edit button does not appear.

Is it possible to edit a grid with only the selected columns in it?

Thanks,
David

Comments

  • With your particular example, it would be impossible because you're thrown away the primary key. There's no way LINQPad can know how to update the rows back to the database.

    Even if you included the primary key, other metadata is lost in the anonymous type, such as the original table name and column mappings.

    The only way I can think right now that LINQPad could support this is to provide an option on the grid itself, e.g., on the context menu, "Choose columns to display". Or another Dump overload that accepts a list of columns.
  • Thanks Joe, the "Choose columns to display" would work. FWIW, SQL Management Studio does allow you to edit a subset of columns. Maybe you could have LinqPad act the same way.
  • Joe, If the select included an Id, could you allow something like this?
    Persons.Select(x=>new{x.Id,x.Name}).Dump<Persons>()
    Or maybe this (multiple grids would be cool as well)
    var grid = new Util.EditGrid<Persons>("Person Edit Grid");
    grid.DataSource = Persons.Select(x=>new{x.Id,x.Name});
    grid.Dump();
  • It still wouldn't work, because you lose the database, schema and table info. The "Persons" class could map to a table called "Person", or "someSchema.Persons", for instance. All the metadata is lost once you project like this.
  • I understand the issue with that approach now. For situations that linqpad cannot create it's own grids for, maybe you could create something similar to DataGrid but displayable in a results tab.
Sign In or Register to comment.