I notice that a raw call to GetPackages() on a repository brings back every package in the source, even if there are multiple versions of the same package.
I can roll the list of packages up into a list of the latest version of each package in a number of ways:
// simple grouping
packages.GroupBy(p => p.Id).Select(g => g.OrderBy(p => p.Version).Last());
// in-build DistinctLast call
In my application I'm doing some rudimentary paging on the list of packages using the Skip() and Take() extension methods, so neither of these attempts seem to work for me.
The first throws an obscure Linq error, probably because I'm trying to do some fancy grouping against an OData feed and the protocol doesn't support it. I can reproduce it if anyone would like to see the actual message.
The second works, but since it happens client side (it's an IEnumerable<T> extension rather than IQueryable<T>) then if a page of results doesn't include all versions of a package, I might be showing the user an out of date version.
Is there a built-in way to query a repository for just the most recent version of each package?