Query Sql in linq

P

Paul

Hi,
How can i di this query in LinQ:

Selec t1.Id, t1.Campo2, t2.IdTabla1
FORM Tabla1 t1 left join Tabla2 t2
ON t1.Id==t2.IdTabla1 OR t1.Id==t2.IdTabla1Bis

It is important the condition of the OR, since without it the will do
is say I've managed to do this:

Selec t1.Id, t1.Campo2, t2.IdTabla1
FORM Tabla1 t1 left join Tabla2 t2
ON t1.Id==t2.IdTabla1

var reultado=from t1 in Tabla1
join t2 in Tabla2
on t1.Id equals t2.IdTabla1 into leftJoin
from t2 in leftJoin.DefaultIfEmpty()
select new
{
Campo1=t1.Id,
Campo2=t1.Campo2,
Campo3=t2.IdTabla1
};

But How can i put "OR"?

Thanks
 
V

vanderghast

It would have been easier to allow the complex ON clause directly (as it
does for the SQL statement) but a work around is to make two queries, the
first one being the complex inner join:



var q1=from t1 in tabla1
from t2 in tabla2
where t1.id == t2.id || t1.id == t2.idbis
select new { ta.id = qid, ... } ;



and THEN, make the left outer join between tabla1 and q1


var reultado = from t3 in tabla1
join t4 in q1 on t3.id = t4.qid
into projection

from x in projection.DefaultIfEmpty()
select new { ... } ;




For performance considerations, compare the resulting execution plan, not
the produced SQL statement.




Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top