Can I make this type of SQL query on LINQ to SQL?
(this query is only a example)
select *
from orders as o
left outer join (select * from ordersdetail where status = 'A') as od
on o.id = od.orderid
What I need is how can I put a subquery inside de “from” statement.
Thanks
Just do the order details condition in the usual way:
(NB. Details is a sequence, with each matching details record, LINQ operators like First and FirstOrDefault can be use to extract just one.)
Or use an expression as the data source
Or even, use another comprehension expression as the source expression:
(Setting you
DataContext‘sLogproperty allows you to see the SQL so you can compare what SQL is actually generated.)EDIT: Change to use Group Join (
... into var) to get the outer join (rather than an inner join).