CROSS APPLY in Linq

2014-11-23 7:42 AM

Quick note: when trying to do a SQL-style CROSS APPLY using linq with a SQL database underneath, the C# linq statement

from a in Table<TableA>()
from b in Table<TableB>()
       .Where(c => c.Id == a.Id).Take(1)
select new { a, b };

is functionally equivalent to the SQL query

SELECT 
     * 
FROM 
    TableA a
    CROSS APPLY 
    (
        SELECT TOP 1
            * 
        FROM
            TableB b 
        WHERE
            b.id = a.id
    ) b