score:0
Accepted answer
string newcolexpression = @"' ' + " + string.join(" + ",groupbycolumns) ; // prepend a space to ensure string concatenation
// e.g. "' ' + id1 + id2"
dt.columns.add("groupby",typeof(string),newcolexpression);
dt = dt.asenumerable()
.groupby(r => r["groupby"])
.select(g => g.orderby(r => r["pk"]).first())
.copytodatatable();
dt.columns.remove("groupby");
Source: stackoverflow.com
Related Query
- General method to select first row from every group in DataTable, give a List of grouping column
- How do I select every 6th element from a list (using Linq)
- LINQ: Select all from each group except the first item
- How to select rows from DataTable based on Index / Row Number?
- How to use Linq to select and group complex child object from a parents list
- How to select multiple columns from datatable in linq group by?
- Select items from a list after the first occurrence of a character
- Select the first rows from a datatable by LINQ
- Group and Select First From Two Tables Linq
- LINQ select from first list
- Select a row from a DataTable and Create New Row to Add to DefaultView
- Select a row in a DataTable and change the header name to a new name and order by first and last names
- Select common elements for 2 or more departments from list group by then having count
- Select entire duplicate row from datatable with linq c#
- How to verify row existence and delete it from DataTable using Linq or Select command?
- LINQ-to-SQL: Select mulitple properties from top row of each GROUP using LINQ query
- select items from first group in collection LINQ (C#)
- Linq: Select from 2 datatable where column id from first table = column id from second table
- Using linq to append list to list from select method
- Using lambda to select top 1 row returned from DataTable
- How to select first n number of columns from a DataTable
- how to get data from datatable by ( select and Group By)
- How to group list of files (strings) by folder and perform select method on the group
- select matched and unmatched row from two datatable
- Foreach look for the first value in the entire list of records. cannot be applied to operator of type method group and bool
- Select first result from one collection using group by and adding into another collection
- Select entire row from 2d object[] where first column value matches
- Linq SELECT query not returning first row of DataTable
- Select Multiple Fields from List in Linq
- How do I get a distinct, ordered list of names from a DataTable using LINQ?
More Query from same tag
- LINQ and 2 datatables
- How to filter a list based on a common property (only then to find the min value)
- LINQ ForEach Statement
- Search and Update XML using multiple condition using linq
- Converting object returned from Linq.Dynamic
- How do i change my LINQ query to show the correct XML?
- Initialize a list from a second llist
- LinQ query select DataRow from DataTable
- Dynamic library using Select method
- Looking for an elegant way to compare two lists and show differences from either side
- How to convert this SQL statement to Linq for C#
- Merging XML Elements with LINQ
- Explain in small words why IQueryable<T> is needed
- C# - Load dictionary of Hashsets from an XML file using Linq
- Parsing XML and cast elements to a typed collection using LINQ, C#
- Optimising LINQ TO SQL (currently it takes around 2 - 3 minutes) for report module?
- LINQ on a DataTable IN a CLR Stored Procedure
- Linq to XML - Returning a subset of xml
- Optimizing a very large LINQ query
- Getting an error specified method is not supported
- How to do a 'search a take best' function in LINQ?
- Method that fetch data from multiple databases running slow
- how to convert UTC dateTime to local datetime
- How to use LINQ to select and transform a subset of a List<T>
- LINQ Recursive query in web api code
- htmlAgilityPack parse table to datatable or array
- Returning LINQ to Entities Query Result as JSON string
- Linq : check for null value before accessing the property
- EF extend query per case
- 2D Array get number of not null rows