3
I have the following tables:
Tabela1 Tabela2 Tabela3 Tabela4 +----+-----------+ +----+-----------+------+------+ +----+-----------+------+------+ +----+-----------+ | Id | Descricao | | Id | Descricao | T1Id | T4Id | | Id | Descricao | T1Id | T4Id | | Id | Descricao | +----+-----------+ +----+-----------+------+------+ +----+-----------+------+------+ +----+-----------+ | 1 | Item1 | | 1 | Item1 | 1 | 1 | | 1 | Item1 | 2 | 2 | | 1 | Item1 | | 2 | Item2 | | 2 | Item2 | 1 | 2 | | 2 | Item2 | 2 | 2 | | 2 | Item2 | +----+-----------+ | 3 | Item3 | 2 | 2 | | 3 | Item3 | 1 | 1 | | 3 | Item3 | +----+-----------+------+------+ +----+-----------+------+------+ +----+-----------+
Both in the Table2 how much in the Table3, the column T4id is a foreign key of the column Id of Table4.
I have the following:
from t1 in db.Tabela1
join t2 in db.Tabela2 on t1.Id equals t2.T1Id
join t3 in db.Tabela3 on t1.Id equals t3.T1Id
join t4 in db.Tabela4 on ((t2.T4Id equals t4.TId) || (t3.T4Id equals t4.TId))
where t1.Id == 1
select t4;
I need to get the data from Table4 based on items from t2 and T3, but cannot use the OR (||)
the way I’ve been doing on the 4th line.
I’m using Entity Framework.
Could someone help me?
Do you really need to do all these joins? Or the query can be rewritten using another approach?
– Leonel Sanches da Silva
Unfortunately I do. But what would that other approach be?
– Jedaias Rodrigues
Don’t do the Join, start the query by Table 4 and not by Table 1.
– Leonel Sanches da Silva
got what he wanted?
– Marco Souza