linqlistentitiesentityset

Using Linq to select a list of Entities, linked Entities, linked Entities


Apologies for the poor question title - I'm not sure how to describe what I'm doing but that is the best I could come up with, please edit it if what I'm asking for has a real name!

I have Programmes, which can have a group of Projects assigned, which in turn have groups of Outputs assigned.

I would like to get all the outputs for the Programme through it's projects as one big list of outputs. I have this:

From pp In Me.ProgrammeProjects Select pp.Project.Outputs

Which basically gets me a list of output lists. (An Ienumerable Of EntitySet Of Output).

I'm brute forcing my way through Linq and can't find any examples of this (or can't recognise one when I see it). How can I do this using just Linq rather than for loops and Linq where I'd go through each EntitySet and add it's contents to a bigger list?

Thanks


Solution

  • Or go against the linq context directly:

    from o in context.Outputs
    where o.Project.ProgrammeProjects.ID = 1
    select o
    

    The reverse will work too and query straight from the data context's table.