views:

455

answers:

3

Hi,

I have two tables in an XML Dataset. T1, T2. Each of the tables has a ID column.

T1 has a list of Customers T2 has a list of Orders

I want to build a LINQ query that returns only the ID of the customers that do not have orders. In other words customer ID's that do not exist in the T2 table.

Oh yea, I'm using C#

Thanks!

A: 

You just need to us a where clause and all:

T1.Where( item1 => T2.All( item2 => item1.ID != item2.ID ) );
bstoney
Looks like that would have worked too! Thanks for the help.
Rick
+2  A: 

I think this will work (please adapt to your DataSets):

var query = from c in T1
            where !(from o in T2 select o.CustomerID)
            .Contains(c.CustomerID)
            select c;
bruno conde
Wow - That was simple! Thanks for the help
Rick
+2  A: 

This requires an outer join and a check on null.

var result = from c in Customers
             join d in Details on d.CustomerID equals c.ID into g
             where !g.Any()
             select c;
Hasan Khan