DynamicLinq build select with subquery

dynamic-linq entity-framework linq

Question

I use System.Linq.Dynamic.Core to dynamically create choose. I want to include one more column (subquery). Can this be done?

I want the same results as this search:

var test = this.DbContext.Countries.Select(t => new
{
    t.Id,
    t.ISOCode,
    lookup = t.Translates.Where(t2 => t2.LangISOCode=="ENG").Select(t2 => t2.Title).FirstOrDefault()
}).ToArray();

I accomplish this:

this.DbContext.Countries.Select("new(Id,ISOCode)").ToDynamicArrayAsync()

however I'm unsure of how to add more subquery columns.

1
1
12/21/2017 1:24:33 PM

Accepted Answer

The remedy is:

await this.DbContext.Countries.Select("new(Id,ISOCode,Translates.Where(LangISOCode=\"SLV\").Select(Title).FirstOrDefault() as translates)").ToDynamicArrayAsync();

I combined the source tests' code to find the answer (select, where, firstordefault).

0
12/21/2017 12:52:46 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