세 개의 테이블에 대해 왼쪽 외부 조인을 수행하려고합니다. 하나의 변수에서 그것을 할 수있는 방법이 있다는 것을 압니다. 그러나 그것을 이해할 수는 없습니다. 대신 두 개의 왼쪽 외부 조인을 수행 한 다음 나머지 조인을 수행했습니다. 여기에 대한 내 코드는 다음과 같습니다.더 나은 방법을 찾고 LINQ의 세 테이블에서 왼쪽 외부 조인
var outerJoin1 =
(from h in resultHours
join u in results on new {h.PhysicalUnitId, h.MonthNum} equals new {u.PhysicalUnitId, u.MonthNum} into outer
from grouping in outer.DefaultIfEmpty()
select new {timeKey = h, Key = grouping});
var outerJoin2 =
(from h in resultHours
join s in serviceHrsResults on new {h.PhysicalUnitId, h.MonthNum} equals new {s.PhysicalUnitId, s.MonthNum} into outer2
from grouping in outer2.DefaultIfEmpty()
select new {timeKey = h, Key = grouping});
var outerJoin =
(from a in outerJoin1
join b in outerJoin2 on new {a.timeKey.PlantId, a.timeKey.MonthNum} equals new {b.timeKey.PlantId, b.timeKey.MonthNum} into outer
from grouping in outer.DefaultIfEmpty()
select new{timeKey = a, Key = grouping}).Distinct();
위의 코드를 하나의 변수에 넣으면 작동하지 않습니다. 다음은 내가 시도한 것입니다 :
var outerjoin =
from h in resultHours
join u in results on new {h.PhysicalUnitId, h.MonthNum} equals new {u.PhysicalUnitId, u.MonthNum} into outer
from grouping in outer.DefaultIfEmpty()
from hr in resultHours
join s in serviceHrsResults on new {hr.PhysicalUnitId, hr.MonthNum} equals new {s.PhysicalUnitId, s.MonthNum} into outer2
from grouping in outer2.DefaultIfEmpty()
select new {timeKey = h && timeKey = hr, Key = grouping};
이 문제는 두 개의 그룹이 충돌하는 것입니다. 난 그냥 선택하기 전에 바로 그룹화가 필요하지만 "그룹화"를 사용하는 방법을 알아낼 수 없어 둘 다 outer.DefaultIfEmpty() 및 outer2.DefaultIfEmpty() 포함 할 꽤 확신 해요.
누군가가 나를 가르쳐 주시면 감사하겠습니다.