What I try to achieve is the following: Filter the ProjektStatus with the where function, the group them by ProjektId. Order the group descending by StatusMonatJahr and then take the first element of each group and return it.
public IEnumerable<ProjektStatus> GetCurrentProjektStatus(Func<ProjektStatus, bool> where)
{
return this.db.ProjektStatus
.Where(where)
.GroupBy(x => x.ProjektId)
.Select(x =>
x.OrderByDescending(y => y.StatusMonatJahr))
.First();
}
Unfortunately, with this query I get the first whole group instead of the first element of each group.
What do I have to change to achieve this?
Thanks in advance