I would like to implement with LINQ C # (Using NHibernate as the following query :
<
return (from t1 in Session.Query<Tabela1>()
join t2 in Session.Query<Tabela2>()
on t1 equals t2.T1
where (from t3 in Session.Query<Tabela3>()
where
t3.Tabela == 1 && t3.Atualizacao >= dataAtualizacao
select t3.Chave).Contains(t1.Id)
/* aqui teria que ser um 'or' (||) ao invés de um 'and' (&&), como é feito por default */
where (from t3 in Session.Query<Tabela3>()
where
t3.Tabela == 2 && t3.Atualizacao >= dataAtualizacao
select t3.Chave).Contains(t2.Id)
select t1).Distinct().ToList();
The query equivalent in SQL that I want to generate would be similar to this:
SELECT * FROM TABELA1 T1
LEFT OUTER JOIN TABELA2 AS T2 ON T2.T1 = T1.ID
WHERE
(T1.ID IN (SELECT T3.CHAVE FROM TABELA3
WHERE T3.CODIGOTABELA = 1 AND T3.ATUALIZACAO >= '10/25/2000 13:05:00')
OR /* Esse OR é que não consigo implementar com LINQ, da maneira que está a expressão LINQ nessa linha gera um AND */
T2.ID IN (SELECT T3.CHAVE FROM TABELA3
WHERE T3.CODIGOTABELA = 2 AND T3.ATUALIZACAO >= '10/25/2000 13:05:00'))
The problem is that I did not find any way to make the expression "OR" between 2 subquerys
, and by default in LINQ the generated expression is an "AND" strong>.
Is there any way to do the OR expression between the two subquerys ?
Note: You could also use Lambda Expressions , instead of LINQ.