Linq Query for return duplicate values or empty values in a specific column from datatable

i want to write a linq query to return duplicate rows or empty values in a specific column from a datatable

input datatable 1 :
ID Value
1 10
2 20
3 10

and the output will be in another datatable
output datatable 2:
ID Value
1 10

we do have some doubts on the output

as 3 10 was not in output only the first from duplicated group. This can be the case as a rule let stay the last one or maybe it was overseen.

Case 1 All duplicated rows and empties will be filtered out

Result | Datatype: List(Of DataRow) = 
(From d in dtData.AsEnumerable
Group d by k=d("Value").toString.Trim into grp=Group
Let hasBlank = grp.Any(Function (x) IsNothing(x("Value")) orElse String.IsNullOrEmpty(x("Value").toString.Trim))
Let doPass = {grp.Count > 1, hasBlank}.Any(Function (b) b)
Where doPass
Select g=grp.ToList).SelectMany(Function (x) x).toList

If Activity | Condition: Result.Count>0
Then: dtResult = Result.CopyToDataTable
Else: dtResult = dtData.Clone

Thank you so much this is work

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.