-2

I have following data

Date          | ProjectTypeID
--------------  -------------
10/31/2016    |     1
11/30/2016    |     2
12/31/2016    |     2
01/01/2016    |     3

What would be the Linq query to get all the dates for ProjectTypeIDs which has dates count > 1

Results should yield me following List of Dates because ProjectTypeID = 2 has two dates associated with it

11/30/2016
12/31/2016

1 Answers1

5

Something like:

var result = data.GroupBy(item => item.ProjectTypeID, item => item.Date)
                 .Where(group => group.Count() > 1)
                 .SelectMany(group => group)
                 .ToList();
Slai
  • 22,144
  • 5
  • 45
  • 53
  • I am getting compile time error on .SelectMany(group => group, item => item.Date) var parentDates = parentObj.GroupBy(c => c.ProjectTypeId) .Where(group => group.Count() > 1) .SelectMany(group => group, item => item.EndDate) .ToList(); – Prasad Koranne Sep 13 '17 at 23:01
  • my bad .. I didn't test it. You can try the updated version – Slai Sep 13 '17 at 23:06