views:

34

answers:

3

I have a list(of t) and I got a iqueryable(of a)

I want to filter out any item from the iqueryable(of a) where a.id = t.myotherid

I'm not really sure how to write this query, anyone could help me here?

For now I got this

Dim listCie = (From c In db.getListCompany() _
                Where Not rels.Select(Function(a) a.ChildID).Contains(c.ID) _
                  And Not rels.Select(Function(a) a.ParentId).Contains(c.ID) _
                Select c)

question is, should I use .Any or is there any better way?

+4  A: 
Dim result = From item In queryable _
             Where Not list.Select(Function(x) x.MyOtherId).Contains(item.Id) _
             Select item
Mehrdad Afshari
Gah...beat me to it.
Justin Niessner
no, wont work already tried this since the list contain an object with different proprieties
Fredou
Close, but it's not comparing based on the id of the list object only. Need to .Select.Any() off the list for that.
Joel Coehoorn
Yeah, didn't notice. Fixed.
Mehrdad Afshari
this work, added one more question above.
Fredou
Fredou: I don't think LINQ to SQL translates `Enumerable.Any`. It just supports `.Contains` for client side collections AFAIK.
Mehrdad Afshari
A: 

I think that what you want to do can be achieved with a join. You can get some examples here

Raúl Roa
+1  A: 
Dim result = From item In queryable _
             Where Not list.Any(Function(t) t.MyOtherID = item.Id) _
             Select item

An alternative is to use the .Intersect() method.

Joel Coehoorn
I updated and add a little more information in my question
Fredou
Joel: I don't think LINQ to SQL is able to handle `Enumerable.Any()`.
Mehrdad Afshari
@Mehrdad, you mean list?
Fredou
`List<T>` does not have an `Any` method. It's an extension method coming from `System.Linq.Enumerable` class.
Mehrdad Afshari
@Mehrdad, good to know! thanks
Fredou