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句の結果を生成しませんが、何が欠けていますか?