-2

i have a table which has product category, product type, and product detail. i want to create a nested array using LINQ query like if it has multiple categories like a burger, pizza etc.

see table

suppose if a category is Pizza then there are 3 types of Pizzas: vegetable, meat, beef, and mixed. then there are different types like 6-inch pizza, 12-inch pizza. I want output like this.

1 pizza :

  > > chicken:
        > > > 6 inch pizza
        > > > 12 inch pizza

  > > vegetable:
        > > > 6 inch pizza
        > > > 12 inch pizza

2 Burger :

   > > Fish:
       > > > Medium
       > > > large
  • Have you tried anything that did not work? – Crowcoder Oct 04 '18 at 20:44
  • i have seen this piece of code var grouped = from v in context.PizzaPizza group v by new { VN = v.Category, VD = v.Type } into grp orderby grp.Key.VN, grp.Key.VD select new { VN_VD = grp.Key, Items = grp }; return grouped; but unable to get desired result – Atif Siddiqi Oct 04 '18 at 20:46
  • 1
    That looks like JSON - I say 'looks like' because as posted it is not valid. But I cant figure out what linq has to do with anything. – Ňɏssa Pøngjǣrdenlarp Oct 04 '18 at 20:50
  • i am working on Web service. i have shared desired result. @New Contributor – Atif Siddiqi Oct 04 '18 at 21:01
  • Your category Pizza seems to have 4 types, not 3. Please don't use images to post data or code. – NetMage Oct 04 '18 at 21:26
  • pizza can have multiple types . sorry i am posting question first time i will take care of it next time – Atif Siddiqi Oct 04 '18 at 21:30
  • 1
    Read over @NewContributor's note. You are showing invalid JSON. There's no C# code and definitely no LINQ. I can't follow. – Flydog57 Oct 04 '18 at 21:31
  • @Flydog57 yes i know it is invalid just post as example. i am writing linq query to fetch data from table. therefore i am saying nested array – Atif Siddiqi Oct 04 '18 at 21:34
  • You don't need to "take care of it next time"; you can edit this post to make it more intelligible. Take your table and format it into "code" so that it's text (that way you don't post a link to an image). Show us what you are talking about. Invalid JSON doesn't really tell us anything. Once people can quickly understand you, they can more quickly respond. – Flydog57 Oct 04 '18 at 21:35
  • @Flydog57 Modified my post – Atif Siddiqi Oct 04 '18 at 21:57

1 Answers1

-1

Just use linq .GroupBy It should give you what you need

bcnbt
  • 60
  • 2
  • 7