I have a many to many relationship between tables A and B.
Since I used code first, the DB table ‘AB’ was automatically created. I don’t have an entity model for it.
How can I, for example, query all the B’s that belong to A.id=x?
Edit:
After I load either A or B, I can easily get references to lists B and A respectively.
My real problem is making a single query that excludes all B’s that are already associated with A.
This is what I want to do:
query.Where(**b.ID NOT IN (SELECT B.ID FROM AB WHERE A=5)** )
I’m sure I could do this with a raw sql query, but I want to be consistent and use IQueryable/LINQ where I can.
You can try this:
It creates the following SQL:
Edit
When using
DbContext(EF >= 4.1) you can inspect the SQL by usingToString()of theIQueryable: