c# - Unable to assemble the query correctly -


3 tables:

  1. parenttable: parentid (assume there's parentid = 5)
  2. parentchildrentable: parentid, childrenid (assume there 3 relation rows of parentid = 5)
  3. childrentable: childrenid, childrenname (assume there 3 children of parentid = 5, example: a,b,c)

im trying "get children of parentid=5 , print names" using entity framework , linq

using pseudo-like mean:

parent fifthparent = db.parenttable.firstordefault(p => p.parentid == 5);  foreach (parentchildren parentchildren in fifthparent.parentchildren) // iterate 3 times {     //get each child seperatly according     foreach(child child in parentchildren.children)     {         //print (on 1st iteration)         //print b (on 2nd iteration)         //print c (on 3rd iteration)     }    } 

as far can see it should 2 for-loops, though im heavy-struggling in last 2 hours. hope u please provide code samples because still can not grasp principle of these queries.

this join , filter return children parent's id 5.

var childrenoffifthparent =      parent in context.parenttable      join parentchild in context.parentchildrentable on parent.parentid         equals parentchild.parentid      join child in context.childrentable on parentchild.childid         equals child.childid      parent.parentid == 5     select child; 

then can like:

foreach (var child in childrenoffifthparent.tolist()) {     // print child } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -