First Table +--------+------------+-------+ | type | variety | price | +--------+------------+-------+ | apple | gala | 2.79 | | apple | fuji | 0.24 | | apple | limbertwig | 2.87 | | orange | valencia | 3.59 | | orange | navel | 9.36 | | pear | bradford | 6.05 | | pear | bartlett | 2.14 | | cherry | bing | 2.55 | | cherry | chelan | 6.33 | +--------+------------+-------+
Second Table +--------+----------+ | type | minprice | +--------+----------+ | apple | 0.24 | | cherry | 2.55 | | orange | 3.59 | | pear | 2.14 | +--------+----------+
select type, min(price) as minprice
from fruits
group by type;
The first table is and example of the data that I have and the second table is what I want to get from the first.
I am using GenericRepository/UnitOfwork to get the data from repository.
repository.fruitRepository.Get().GroupBy(m => m.type);
But I can only get the type field but I want to get more fields.
Do I need to use a select clause before groupby? If yes, how can I select more fields?
The GroupBy method returns more data, but it’s returned as an enumerable… you may be able to pull what you want out of it with a Select after the GroupBy…
Or if you prefer a LINQ statement: