c# - LINQ group by query help: Select another related table with key -


please me complete following query:

var results = species in db.species               join cats in db.categories on species.categoryid equals cats.categoryid               join groups in db.groups on cats.groupid equals groups.groupid               group groups groups g               select new groupwithcategorychildren               {                   group = g.key,                   categories = (cats above query same g.key group)???               }; 

i sql, i'm struggling linq. want end list of each group along cats joined in above/main single query, ideally without re-querying data again in separate query.

thanks lot

i'm not sure understood correctly think need: instead of group groups groups group cats groups , key groups , values of group matching categories.

var results = species in db.species               join cats in db.categories on species.categoryid equals cats.categoryid               join groups in db.groups on cats.groupid equals groups.groupid               group cats groups g               select new groupwithcategorychildren               {                   group = g.key,                   categories = g.tolist()               }; 

i used test it:

list<dynamic> species = new list<dynamic>() {     new { = "1", categoryid = 1 },     new { = "2", categoryid = 2 }, };  list<dynamic> categories = new list<dynamic> {     new { b = "1", categoryid = 1, groupid = 1 },     new { b = "2", categoryid = 2, groupid = 1 }, };  list<dynamic> groups = new list<dynamic> {     new { c = "1", groupid = 1 } };  //result: { group: { c = "1", groupid = 1 }, categories (1,2)} 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -