Chris said:
Anyway, I have sql query:
select * from tab n
join
(
select a, b, c from tab
where a in (select x from tab2 where y=z)
)m
on n.a=m.a
I want to have this query in linq to sql. Can u help me? I have problems
how
to write where in (<select>) clause and then join it.
You dont't have subqueries in linq, so you will need to rewrite your code
as a join. If I am not mistaken, your query can be rewritten in some way
similar to the following (and if I am mistaken, just ask the question in one
of the Sql forums and someone will tell you how to refactor your query so
that the subclause is converted into a join):
select tab1.*, tab2.a, tab2.b, tab2.c from tab1
join tab2 on tab1.a=tab2.a
join tab3 on tab2.a=tab3.x
where tab3.y=z
Once your query is refactored in this way, you can easily express it in
LINQ:
var q = from v1 in cts.tab1
join v2 in ctx.tab2 on v1.a equals v2.a
join v3 in ctx.tab3 on v2.a equals v3.x
where v3.y==z
select new {v1, v2.a, v2.b, v2.c };