I'm having problems querying many-to-many relationships in Linq To Entities. I am basically trying to replicate this query using Linq:
Select * FROM Customer LEFT JOIN CustomerInterest ON Customer.CustomerID = CustomerInterest.CustomerID LEFT JOIN Interest ON CustomerInterest.InterestID = Interest.InterestID WHERE Interest.InterestName = 'Football'
I looked through the network and did not find suitable examples of how to do this. The closest I have:
List<Customer> _Customers = (from _LCustomers in _CRM.Customer.Include("CustomerInterest.Interest") where _LCustomers.CustomerInterest.Any(x => x.Interest.InterestName == "Football") select _LCustomers).ToList();
The problem is that if the client has more than one interest, and one of them is “Football”, then they all return. I also looked at All (), which has the opposite problem, that is, it will only return if they have interest, and this is football, if they have two, and one of them is not football, nothing returns .
Does anyone have any idea?
left-join linq-to-entities entity-framework many-to-many
JD.
source share