List<APList> List = new List<APList>() --
List = statement.APList.Where(f => f.PeriodKey == periodkey
&& f.ClassKey == classkey
&& f.ClassKey != null)
.GroupBy(g => new { g.PostKey})
.Select(s => s.First()).ToList();
foreach (var item in List)
{
item.ClassKey = null;
}
--data
periodkey(int) postkey(int) classkey(int?)
101 12 10
100 12 11
101 11 10
100 11 11
--expected
periodkey postkey classkey
101 12 null
100 11 null
This is working but i dont want to use foreach loop .Is there a better way to optimize the query and write it in a single linq query using Lambda expressions.
.
– user3920526 Jul 24 '17 at 14:23