LINQ - How to select with subquery -



LINQ - How to select with subquery -

my info is:

+-----+--------+-----------+ | id | name | parentid | +-----+--------+-----------+ | 1 | | 0 | | 2 | b | 0 | | 3 | c | 1 | +-----+--------+-----------+

how c if have parentid = 0 linq?

assuming "categories" collection name, think need.

var parentcategoryids = collections.where(c => c.parentid == 0).select(c => c.id); var results = collections.where(c => parentcategoryids.contains(c.parentid));

and if want name, can do

var names = results.select(r => r.name);

these 3 statements written 1 linq statement did clarity.

linq

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -