Posts

Showing posts with the label left-join

T-SQL to LINQ to SQL using Navigation Properties

Image
Clash Royale CLAN TAG #URR8PPP T-SQL to LINQ to SQL using Navigation Properties I can’t seem to come up with the right corresponding LINQ to SQL statement to generate the following T-SQL. Essentially, I'm trying to return payment information with only one of the customer's addresses... the AR address, if it exists, then the primary address, if it exists, then any address. SELECT < payment and address columns > FROM Payment AS p INNER JOIN Customer AS c ON c.CustomerID = p.CustomerID OUTER APPLY ( SELECT TOP 1 < address columns > FROM Address AS a WHERE a.person_id = c.PersonID ORDER BY CASE WHEN a.BusinessType = 'AR' THEN 0 ELSE 1 END , a.IsPrimary DESC END ) AS pa WHERE p.Posted = 1 We’re usin...