Friday, June 9, 2017

query child objects inside of a query for an IQueryable

var query  =  from i in DbContext.Infected.Where(x => x.Id == somethingErOther)
join t in (
   from w in DbContext.Tapeworms
   select new
   {
      Fk_Id = w.VictimId,
      Result = new TapewormDTO()
      {
         Name = w.Name,
         Length = w.Length,
         Variation = w.Variety
      }
   })
on i.Id = t.Fk_Id into TapewormResult
join c in DbContext.Cities.Where(x => x.Id == i.CityId)
select new InfectedDTO()
{
   Name = i.Name,
   Locale = c.Name,
   Tapeworms = TapewormResult.Select(x => x.Result).ToList()
};

No comments:

Post a Comment