public static IQueryable <TV> GroupAndSelect <T, TU, TV>(this IQueryable <T> query, GroupBySelector <T, TU, TV> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            var grouping   = selector.GroupBy().ResolveEmbedded();
            var expression = selector.BuildExpression().ResolveEmbedded();

            return(query.GroupBy(grouping).Select(expression));
        }
        public static Task <Dictionary <TU, TV> > GroupByDictionaryAsync <T, TU, TV>(this IQueryable <T> query, GroupBySelector <T, TU, TV> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            var grouping   = selector.GroupBy().ResolveEmbedded();
            var expression = selector
                             .BuildExpression()
                             .ResolveEmbedded()
                             .Compile();

            return(query.GroupBy(grouping).ToDictionaryAsync(x => x.Key, expression));
        }