Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have the following Two tables.

Person : { PersonId, FirstName, LastName}
Phone : { PhoneId, PersonIdFK, Number, IsActive}

In a classic SQL, you would write the following SQL statement to retrieve data and active phone numbers for a given person.
SQL
SELECT PersonId,FirstName, LastName, PhoneId, Number
FROM   Person left outer join Phone
ON     Person.PersonId = Phone.PersonIdFK and IsActive=1
Where  PersonId=123


Question:

How can I achieve this SQL statemnet in Entity Framework (LINQ to Entities)

So far I have written the following code which works.
VB
var query = from Person in dbContext.Persons
            join Phone in dbContext.Phones
            on Person.PersonId equals Phone.PersonIdFK
            where Person.PersonId=123


However, I'm unable to find a way to put a second condition on the "on" key word like this
VB
on Person.PersonId equals Phone.PersonIdFK && Phone.IsActive == 1

Does Entity Framework even supports multiple conditions on a join?
Posted
Updated 28-Feb-12 10:16am
v2
Comments
André Kraak 28-Feb-12 16:17pm    
Edited question:
Added pre tags
Spelling/Grammar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900