KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to understand left outer joins in LINQ to Entity. For example I have the following 3 tables: Company, CompanyProduct, Product The CompanyProduct is linked to its two parent tables, Company and Product. I want to return all of the Company records and the associated CompanyProduct whether the CompanyProduct exists or not for a given product. In Transact SQL I would go from the Company table using left outer joins as follows: SELECT * FROM Company AS C LEFT OUTER JOIN CompanyProduct AS CP ON C.CompanyID=CP.CompanyID LEFT OUTER JOIN Product AS P ON CP.ProductID=P.ProductID WHERE P.ProductID = 14 OR P.ProductID IS NULL My database has 3 companies, and 2 CompanyProduct records assocaited with the ProductID of 14. So the results from the SQL query are the expected 3 rows, 2 of which are connected to a CompanyProduct and Product and 1 which simply has the Company table and nulls in the CompanyProduct and Product tables. So how do you write the same kind of join in LINQ to Entity to acheive a similiar result? I have tried a few different things but can't get the syntax correct. Thanks.
Tags (comma-separated)
Save Edits
Cancel