加入Linq中不存在的地方c#

时间:2016-12-21 08:03:40

标签: c# mysql linq

如何将其转换为linq c#,

select * from boliviaextremocontabilidad.subrecurso as sr where not exists 
(select * from boliviaextremocontabilidad.recursocliente as rc 
join  boliviaextremocontabilidad.eventocliente as ec on rc.idVenta=ec.idVenta
 where rc.idSubrecurso=sr.idSubrecurso and ec.idEvento = 9 ); 
仅限

select * from boliviaextremocontabilidad.subrecurso enter image description here

我想要的是这个:

select * from boliviaextremocontabilidad.subrecurso as sr where not exists 
    (select * from boliviaextremocontabilidad.recursocliente as rc 
    join  boliviaextremocontabilidad.eventocliente as ec on rc.idVenta=ec.idVenta
     where rc.idSubrecurso=sr.idSubrecurso and ec.idEvento = 9 ); 

enter image description here

我正在尝试一切,但我不知道,如何结合"加入"用"哪里不退出"

这些是我在linq中尝试的代码,但任何人都可以工作:

尝试1:

(from sr in db.subrecurso 
join rc in db.recursocliente on sr.idSubrecurso equals rc.idSubrecurso
join ec in db.eventocliente on rc.idVenta equals ec.idVenta
where ec.idEvento == idEvento && !db.recursocliente.Any(m => m.idSubrecurso == sr.idSubrecurso)
select sr).ToList();

尝试2:

List<subrecurso> srall=(from sr in db.subrecurso
                                             where !db.recursocliente.Any(m => (m.idSubrecurso == sr.idSubrecurso))
                                             select sr).ToList();
                List<subrecurso> srcs = (from sr in  srall
                                        join rc in db.recursocliente on sr.idSubrecurso equals rc.idSubrecurso
                                        join ec in db.eventocliente on rc.idVenta equals ec.idVenta
                                        where ec.idEvento == idEvento
                                        select sr).ToList();

尝试3:

List<subrecurso> srcs = (List<subrecurso>)(from sr in db.subrecurso
                                                       where !db.recursocliente.Any(m => (m.idSubrecurso == sr.idSubrecurso))
                                                       select sr)
                                     .Join(db.recursocliente.Join(db.eventocliente.Where(ec => ec.idEvento == idEvento), rc => rc.idVenta, ec => ec.idVenta, (ec, rc) => new { ec, rc })
                                     , sr => sr.idSubrecurso, rc => rc.ec.idSubrecurso, (sr, rc) => new List<subrecurso> { sr });

非常感谢!!

0 个答案:

没有答案