开发者

How to get object collection from another collection?

开发者 https://www.devze.com 2023-04-04 06:42 出处:网络
Suppose I have a collection defined as: IEnumerable<Employee> Employees; Entity Employee has property Person.

Suppose I have a collection defined as:

IEnumerable<Employee> Employees;

Entity Employee has property Person. I have loaded E开发者_如何学Gomployees from Ria service including Person with eager-loading. Now I want to get the collection of Person from Employees, something like

IEnumerable<Person> People = Employees.Person;

How to use Linq to get all Person? any other solution for this case?


Unless I'm missing something, it should be as easy as (assuming Person isn't another collection):

var persons = Employees.Select(e => e.Person);


Try the following

IEnumerable<Employee> collection = ...;
IEnumerable<Person> persons = collection.Select(x => x.Person);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号