0

I'm trying to remove from a datatable the duplicated lines, but without taking into account a column into the duplication filter.

Example :

| Name | Region |
| Toto |   5    |
| Toto |   2    |
| Toto |   1    |
| Gege |   2    |

What I'm searching for if to filter it as the following

| Name | Region |
| Toto |   5    |
| Gege |   2    |

Thank for your help.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dremor
  • 789
  • 2
  • 8
  • 27

2 Answers2

0

Try this

var filteredData = data.GroupBy( d=> d.Name).SelectMany(grouping => grouping.First());

Depending upon LinqProvider for the database (IQueryable implementation), The query may run on database, or on client side( if so, there will be memory/network bandwidth issues).

In some case, not all Linq constructs are supported.

Tilak
  • 30,108
  • 19
  • 83
  • 131
0

Try:

datatable.GroupBy(x => x.Name);

you need to add a using for the System.Linq namespace.