How can I use Dynamic Linq to project sub collections?

c# dynamic-linq linq

Question

I know how to get Dynamic Linq to project sub (non-collection) objects, e.g.

"new(new(CustomerStat.ID) as CustomerStat)", where CustomerStat is a non-collection object.

I'd like to do the something similar with collections, e.g. "new(LocationId, new(Employees.Select(FirstName)) as Employees)", which would return a projected list of locations, with sublists of employees, containing just their first name.

Or in other words, I'd like the DynamicLinq version of the following:

  var locations = (new CompanyContext().Locations.
    Select(l => new {l.ID, Emps = l.Employees.Select(e=>e.FirstName)}));

Thanks!

1
0
7/9/2015 3:41:58 PM

Accepted Answer

We ended up having to modify DynamicLinq to support this feature.

We've made a pull request with the new feature. Code can be found here.

0
7/9/2015 7:08:53 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow