這應該千方百計想讓你想要的:
var notInT2 = T1.Where(i => T2.All(e => e.T1ID != i.Id) &&
T2.All(e => e.PT1ID != i.Id));
爲了測試它:
class RowT1 { public Int32 Id;}
class RowT2 { public Int32 T1ID; public Int32 PT1ID; }
class Programm
{
static void Main()
{
var T1 = new List<RowT1>(){new RowT1(){Id=1},
new RowT1(){Id=2},
new RowT1(){Id=3},
new RowT1(){Id=4}};
var T2 = new List<RowT2>(){new RowT2(){T1ID=2, PT1ID=1},
new RowT2(){T1ID=3, PT1ID=2}};
var notInT2 = T1.Where(i => T2.All(e => e.T1ID != i.Id) &&
T2.All(e => e.PT1ID != i.Id));
Console.ReadLine();
}
}
你的意思是你需要一個外連接嗎?如果你能顯示你的linq代碼會很有幫助。 – 2010-10-04 09:49:07
我認爲他的意思是'select * from T1 where not exists(select * from T2 where T2.T1ID = T1.ID)並且不存在(select * from T2 where T2.PT1ID = T1.ID)' - 除了LINQ – Rup 2010-10-04 09:50:10