Link to home
Start Free TrialLog in
Avatar of Mike_Mozhaev
Mike_Mozhaev

asked on

Is it possible to use derived tables in LINQ 2 SQL?

Is it possible to get something like the following in LINQ 2 SQL?

SELECT e.A, d.B
FROM
(
      SELECT * FROM Event
      WHERE ID BETWEEN 1 AND 21
) e
LEFT OUTER JOIN EventDetail d ON e.ID = d.EventID
Avatar of Chris M
Chris M
Flag of Uganda image

Yes. You can create a view as follows:

CREATE VIEW MY_VIEW AS
SELECT e.A, d.B
FROM
(
      SELECT * FROM Event
      WHERE ID BETWEEN 1 AND 21
) e
LEFT OUTER JOIN EventDetail d ON e.ID = d.EventID

Then go to linq and simply run SELECT * FROM MY_VIEW.

Cool stuff.
Avatar of Mike_Mozhaev
Mike_Mozhaev

ASKER

Thanks, that will work.
But I'm looking for way to express it in LINQ without any SQL since this way I have strong typing.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It works, though without derived table. But I haven't found any other way so I'll use this approach.
Thanks