I have two tables that are not related using a foreign key but should be joinable. The relation (not FK) is one-to-many. Example:
Parent <- 1-to-many -> Child
- I would like to query parents while joining children, even if they don’t have children (left join?).
- I would like to select a
parentwhile manually setting thechildrenproperty through some action
Sample:
using(var context = new Test.Models.Ef.Entities())
{
var products = from p in context.Parent
join c in context.Child on p.key equals c.parentkey
select new {Parent = p, Child = c};
}
Questions:
- How do I “left join” the context.Child table in the above example?
- How do I “group” the children by parent, while manually selecting it’s children in a property?
- Pseudo:
select p => p.Children = select c group by p
- Pseudo:
This executes a GroupJoin, which translates to an outer join.