Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql LINQ-Where子句中具有多个参数的左外部联接_Sql_Linq_Llblgenpro - Fatal编程技术网

Sql LINQ-Where子句中具有多个参数的左外部联接

Sql LINQ-Where子句中具有多个参数的左外部联接,sql,linq,llblgenpro,Sql,Linq,Llblgenpro,如何在LINQ中执行此SQL查询: select * from chat c left outer join lead s on c.key = s.id where (typeId = 5 AND c.key = @clientId) OR (c.typeId = 4 AND s.clientId = @clientId) 或者这个SQL查询——相同,相同 select * from chat c where (typeId = 5 AND c.key = @clientId) OR (ty

如何在LINQ中执行此SQL查询:

select * from chat c
left outer join lead s on c.key = s.id
where (typeId = 5 AND c.key = @clientId) OR (c.typeId = 4 AND s.clientId = @clientId)
或者这个SQL查询——相同,相同

select * from chat c
where (typeId = 5 AND c.key = @clientId) OR (typeId = 4 AND c.key in (select id from lead where clientId = @clientId))
我所拥有的:

var chatter = (from chat in linq.Chat
             join lead in linq.Lead
                on chat.key equals lead.Id.ToString() into clientLeads
                from cl in clientLeads.Where(l => l.clientId == clientId).DefaultIfEmpty()
            where (chat.typeId == 5 && chat.key == clientId.ToString()) ||
                (chat.typeId == 4 && chat.key == cl.Id.ToString())
                select chat).WithPath(prefetchPath).OrderByDescending(c => c.CreatedDate);

上面的LINQ查询没有从后面的WHERE子句中得到任何结果,我缺少了什么?

我将第二个查询转换为LINQ:

var leadIds = linq.Lead.Where(l => l.clientId == clientId.ToString()).Select(l => l.id);
var chatter = from chat in linq.Chat
              where (chat.typeId == 5 && chat.key == clientId.ToString()) ||
                    (chat.typeId == 4 && leadIds.Contains(chat.key));

我将第二个查询翻译为linq:

var leadIds = linq.Lead.Where(l => l.clientId == clientId.ToString()).Select(l => l.id);
var chatter = from chat in linq.Chat
              where (chat.typeId == 5 && chat.key == clientId.ToString()) ||
                    (chat.typeId == 4 && leadIds.Contains(chat.key));

老兄,我真的试过一些非常接近的东西,但我一定把它搞砸了!这管用!老兄,我真的试过一些非常接近的东西,但我一定把它搞砸了!这管用!