我有以下表格
tasks
id | name | proj_id
1 | task1 | 1
2 | task2 | 1
3 | task3 | 1
projects
id | name
1 | sample proj1
2 | demo project
budget_versions
id | version_name| proj_id
1 | 50 | 1
budgets
id | cost | budget_version_id | task_id
1 | 3000 | 1 | 2
2 | 5000 | 1 | 1
我需要使用实体框架加入这些表以获得如下结果
task_id | task_name | project_id | budget_version | budget_id | cost
1 | task1 | 1 | 1 | 2 |5000
2 | task2 | 1 | 1 | 1 |3000
3 | task3 | 1 | NULL | NULL |NULL
select tsk.id,tsk.name, tsk.project_id, bgtver.id, bgt.id, bgt.cost
from TASK tsk
left outer join BUDGET_VERSIONS bgtver
on tsk.project_id= bgtver.project_id
left outer join BUDGETS bgt
on bgtver.id = bgt.budget_version_id and tsk.id = bgt.task_id
where bgtver.id = 1
这是我迄今为止尝试过的
var budgetlists = _worker.Budgets.Get().GroupJoin(
_worker.BudgetVersions.Get(),
rb => rb.budget_version_id,
rbv => rbv.id,
(rb, rbrbv) => new {rb, rbrbv}
).SelectMany(
@t => @t.rbrbv.DefaultIfEmpty()
).GroupJoin(
_worker.Tasks.Get(),
rbrbv => rbrbv.id,
tsk => tsk.id,
(rbrbv, tskrb) => new {rbrbv, tskrb}
).SelectMany(
@p => @p.tskrb.DefaultIfEmpty());