using System.Collections.Generic;
public static void Main()
var achievements = new List<Achievement>
new Achievement { Id = Guid.NewGuid(), VerticalId = new Guid("51695B72-C577-4AD9-A7B3-2043261E3917"), PlanType = PlanType.Foundation },
new Achievement { Id = Guid.NewGuid(), VerticalId = new Guid("51695B72-C577-4AD9-A7B3-2043261E3917"), PlanType = PlanType.Intermediate },
new Achievement { Id = new Guid("efa587da-7e4f-40d3-8ccc-2cb12fae0f6d"), VerticalId = new Guid("51695B72-C577-4AD9-A7B3-2043261E3917"), PlanType = PlanType.Advanced },
new Achievement { Id = Guid.NewGuid(), VerticalId = new Guid("2E36410E-A9F9-404C-A80E-4D8F12E5BBD4"), PlanType = PlanType.Foundation },
new Achievement { Id = Guid.NewGuid(), VerticalId = new Guid("2E36410E-A9F9-404C-A80E-4D8F12E5BBD4"), PlanType = PlanType.Intermediate },
new Achievement { Id = new Guid("ad8f387a-e1d7-462b-92b8-9c5c99075a93"), VerticalId = new Guid("2E36410E-A9F9-404C-A80E-4D8F12E5BBD4"), PlanType = PlanType.Advanced }
var filteredAchievements = achievements
.GroupBy(g => g.VerticalId)
.Select(s => new Achievement
PlanType = s.Max(row => row.PlanType)
foreach (var value in filteredAchievements)
var achievement = achievements
.FirstOrDefault(q => q.VerticalId == value.VerticalId && q.PlanType == value.PlanType);
value.Id = achievement.Id;
value.UserProfileId = achievement.UserProfileId;
value.CreatedDateTime = achievement.CreatedDateTime;
filteredAchievements.Select(s => new { s.VerticalId, dep = s.PlanType.ToString(), s.Id })
public Guid Id { get; set; }
public Guid UserProfileId { get; set; }
public Guid VerticalId { get; set; }
public PlanType PlanType { get; set; }
public DateTime CreatedDateTime { get; set; }