Here is my scenario (Tables):
Orders
======================
Id (int)
description (varchar)
Products
======================
Id (int)
description (varchar)
OrderProductXREF (cross reference table)
======================
ProductId (int)
OrderId (int)
I think you get an idea. Nothing unusual is here.
When imported to EDMX file OrderProductXREF table is not visible entity. All I see is navigational properties: Products for entity Order and Orders for entity Product.
So, my problem:
I need Linq and/or Lambda statement that will list all Products that don’t have any Orders associated with. Or, list all Products that are never ordered.
SQL would go like this:
SELECT * FROM Products
WHERE Id NOT IN
(SELECT ProductId
FROM OrderProductXREF)
EDIT:
Uh… sorry forgot one little detail in my question.
Here is the new SQL:
SELECT * FROM Products
WHERE Id NOT IN
(SELECT ProductId
FROM OrderProductXREF
WHERE OrderID = 1)
In words, All Products that are NOT ORDERED in order with ID = 1
Thanks
Apologies – misread the question beforehand. I suspect you want:
You should definitely check the generated SQL though. I would expect it to be sensible, but if it’s not, you would probably want to look at other alternatives.
EDIT: To check products not in order ID 1, you could probably use:
Or: