I created a Web Api in VS 2012. I am trying to get all the value from one column "Category", that is all the unique value, I don't want the list to be returned with duplicates.
I used this code to get products in a particular category. How do I get a full list of categories (All the unique values in the Category Column)?
public IEnumerable<Product> GetProductsByCategory(string category)
{
return repository.GetAllProducts().Where(
p => string.Equals(p.Category, category, StringComparison.OrdinalIgnoreCase));
}
get products by category
, of course theproducts
you got should have the samecategory
, what's distinct here? – King King Oct 23 '13 at 17:26IEnumerable<string>
which you can iterate through to print the full list ofdistinct Categories
. – King King Oct 23 '13 at 17:34public IEnumerable<Product>
topublic IEnumerable<string>
– King King Oct 23 '13 at 17:44