我正在尝试将第一个查询的结果排除在第二个查询的结果中。
SQL等效于此处,其中A是我当前的查询,B是旧查询。
我一直在尝试使用这个guide进行左连接,但我似乎无法弄清楚它在我的情况下应该如何工作。我只是不明白这应该如何工作(我不能让语法突出显示为快乐)。
var emp = from employee in empl
join jc in jce on callout.job_class_code_fk equals jc.job_class_code_fk
join av in ab on employee.employee_id_pk equals av.employee_id_fk
join sh in sho on employee.employee_id_pk equals sh.employee_id_fk into lj
from rnd2 in lj.DefaultIfEmpty()
orderby employee.seniority descending
select new
{
eid = employee.employee_id_pk,
sen = employee.seniority,
nam = employee.employee_name,
pho = employee.phone_number,
lje = sho == null ? sho.employee_id_fk : null //left outer join with exclusion??
};
编辑::根据评论中的建议,我尝试了以下两种方法。虽然我不再有语法问题,但以下都没有返回任何结果,所以这里仍然有问题。
var emp = from employee in empl
join jc in jce on callout.job_class_code_fk equals jc.job_class_code_fk
join av in ab on employee.employee_id_pk equals av.employee_id_fk
join sh in sho on employee.employee_id_pk equals sh.employee_id_fk into lj
from rnd2 in lj.DefaultIfEmpty() where sho == null
orderby employee.seniority descending
select new
{
eid = employee.employee_id_pk,
sen = employee.seniority,
nam = employee.employee_name,
pho = employee.phone_number,
};
var emp = from employee in empl
join jc in jce on callout.job_class_code_fk equals jc.job_class_code_fk
join av in ab on employee.employee_id_pk equals av.employee_id_fk
join sh in sho on employee.employee_id_pk equals sh.employee_id_fk into lj
from rnd2 in lj.DefaultIfEmpty() where rnd2 == null
orderby employee.seniority descending
select new
{
eid = employee.employee_id_pk,
sen = employee.seniority,
nam = employee.employee_name,
pho = employee.phone_number,
};
答案 0 :(得分:0)
好的(对我而言)最容易阅读和理解的答案最终就是这样。
创建两个列表,我要排除的列表和主列表。
他们我们运行master.Except(排除)和瞧。我们已经完成了左外连接的效果而已被排除。
这是工作代码。上面的解决方案很可能有效,因为第一个列表的组合方式存在另一个问题。
0