c# - Select detail from master-detail list using lambda -
below sample data. 2 companies having 2 employees.
list<company> companies = new list<company> { new company { name = "abc company", address = "no.1 st. usa", employees = new list<employee> { new employee { name = "john", age = 30 }, new employee { name = "david", age = 20 } } }, new company { name = "def company", address = "no.2 st. usa", employees = new list<employee> { new employee { name = "michael", age = 22 }, new employee { name = "jason", age = 27 } } } };
i try retrieve employees using following syntax:
var employees = companies.select(c => c.employees).tolist();
however, gives me
the name 'employees' not exist in current context
when watch @ run time. expected result list<employee>
having 4 employees. suggestions appreciated.
you should use selectmany
instead of select
.
the error show has nothing query. not in right scope when trying watch variable.
Comments
Post a Comment