DynamicLinq build select with subquery

dynamic-linq entity-framework linq

Question

I dynamically build select with System.Linq.Dynamic.Core. I want to add another column (subquery). Is this possible?

I need to get same results as this query:

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 get this far:

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

but not sure how to add additional subquery column.

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

Accepted Answer

Solution is:

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

I found solution by combing code from source tests (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