c# - Get object from sub list -
i have following data structure. object contains list of b. b contains list of c.
a { int id; list<b>; } b { int id; list<c>; } c { int id; } i have object a, , have b.id, , c.id want find. have linq this:
a = somemethodtogeta(); int bid = 2; int cid = 20; b foundb = a.b.where(item => item.id = bid).first() c foundc = b.c where(item => item.id = cid).first() i wondering if there way perform above statements single linq statement.
sure, chain 2 single queries:
c foundc = a.b.single(item => item.id == bid) .c.single(item => item.id == cid) this throw exception if there not matching b or matching c within b, original queries also. if issues original query (adding null-checking) may more straight-forward.
Comments
Post a Comment