tags:

views:

62

answers:

2

I have a simple set of tables...

List
- Id

Items
- Id

Entries
- EntryId
- ListId
- ItemId

I'm trying to design a Linq query that will take a given ListId and return all of the Items that do not have an Entry with that ListId on it. It sounds pretty simple, but it keeps coming up wrong. Any ideas?

+1  A: 

If you want to select all Items you could do something like this.

var x = Items.Where(item => !Entries.Any(entry => entry.ItemID == item.ID && entry.ListID == listID));
Quintin Robinson
Well, that just returns entries, not actual items.
Stacey
Okay yeah I thought you might want the items, I added the example for that and will remove the first example.
Quintin Robinson
Stacey
Nevermind, I typed in the data wrong... I think this is exactly what I am looking for. I'm trying to read it closely to see if I understand what it is doing.
Stacey
Sure, you are selecting from the Items table predicated on the fact that you only want items where there aren't any Entries matching an Item.ID where the Entry's ListID is the listID you are trying to exclude.
Quintin Robinson
A: 
var itemsToExclude = from dc.Lists in dc select l;

var x= from Entries in dc select e where !itemsToExclude.Contains(e.ListId)
Johannes Rudolph