views:

106

answers:

1

What is the most efficient way to return a query where the result set is those records that do NOT have an associated record? I am using LINQ and Visual Basic and have been trying to construct a left outer join and then filter on those records whose id is nothing or null in the associated table but am so new to this that I can't get anything to work.

Want to do something like:

Dim query = From s In db.spaces _
    Group Join t In db.tickets On s.spaceid Equals t.spaceid Into rs = Group _
    Select rs
End Function

I want to return the entire left table minus this result set but am a real noob and am stuck.

A: 

Off the top of my head, hope its right!!

Dim query = From s In db.spaces _
Group Join t In db.tickets On s.spaceid Equals t.spaceid Into rs = Group _
from xyz in rs.DefaultIfEmpty _
Select xyz
Dve
Dave, thanks for reply. This returns 22 results (there are 15 records in left table). maybe need to add distinct somewhere?
Brad
Hi Brad, maybe I misunderstood. Are you trying to select the records from tickets that arent joined to a space?
Dve