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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -