我試圖用這個sample:左外LINQ的加入不DefaultIfEmpty
我要的是唯一的回報:'the書使用id = 2
new Book{BookID=2, BookNm=".NET and COM for Newbies"},
我想只有那些沒有訂單的書。
當我刪除DefaultIfEmpty()它也不起作用。
UPDATE
Person magnus = new Person { FirstName = "Magnus", LastName = "Hedlund" };
Person terry = new Person { FirstName = "Terry", LastName = "Adams" };
Person charlotte = new Person { FirstName = "Charlotte", LastName = "Weiss" };
Person arlene = new Person { FirstName = "Arlene", LastName = "Huff" };
Pet barley = new Pet { Name = "Barley", Owner = terry };
Pet boots = new Pet { Name = "Boots", Owner = terry };
Pet whiskers = new Pet { Name = "Whiskers", Owner = charlotte };
Pet bluemoon = new Pet { Name = "Blue Moon", Owner = terry };
Pet daisy = new Pet { Name = "Daisy", Owner = magnus };
// Create two lists.
List<Person> people = new List<Person> { magnus, terry, charlotte, arlene };
List<Pet> pets = new List<Pet> { barley, boots, whiskers, bluemoon, daisy };
var query = from person in people
join pet in pets on person equals pet.Owner into gj
where !gj.Any()
select person;
我只是嘗試這樣的代碼,它似乎它的作品!
我退回了人阿琳她沒有寵物!
有人可以證實這是一種已知的方法嗎?我剛發明它LOL
你的代碼在哪裏? –
它與我粘貼的鏈接相同的代碼...在我看來,這個鏈接沒有提供真正的左連接。我只想在沒有訂單的情況下退還書籍。 – Elisabeth
看到我的更新! ... – Elisabeth