Movements
and Equipment
...
Movements
have Equipment
.Movements
that do have Equipment
.OUTER JOIN
so I can access all of the Movements
even if they do not have any Equipment
.Movements
that have matching Equipment
records in the bridge table.Movements = (
from mvmt in applicationDbContext.Movements
join mvmteq in applicationDbContext.MovementEquips on mvmt .MvmtId equals mvmteq.MvmtId
join equip in applicationDbContext.Equipment on mvmteq.EquipId equals equip .EquipId
orderby mvmt.MvmtId
select new Movement
{
MvmtId = mvmt.MvmtId,
MvmtDescr = mvmt.MvmtDescr
})
.ToList();
var query =
from mvmt in applicationDbContext.Movements
join mvmteq in applicationDbContext.MovementEquips on mvmt.MvmtId
equals mvmteq.MvmtId
join equip in applicationDbContext.Equipment on mvmteq.EquipId equals
equip.EquipId into g
from mvmteq in g.DefaultIfEmpty()
where mvmt.MvmtId != null
select new
{
MvmtId = mvmt.MvmtId,
MvmtDescr = mvmt.MvmtDescr
}).ToList();
Please refer to https://learn.microsoft.com/en-gb/dotnet/csharp/linq/perform-left-outer-joins
and