當我使用下面的代碼時,我多次獲得相同的項目。使用LINQ選擇唯一項目
XElement neededFiles = new XElement("needed",
from o in _9nFiles.Elements()
join t in addedToSitePull.Elements()
on o.Value equals
t.Value
where o.Value == t.Value
select new XElement("pic", o.Value));
我想只得到獨特的項目。我看到堆棧溢出帖子,How can I do SELECT UNIQUE with LINQ?,使用它,我試圖實現它,但改變沒有影響。
代碼:
XElement neededFiles = new XElement("needed",
(from o in _9nFiles.Elements()
join t in addedToSitePull.Elements()
on o.Value equals
t.Value
where o.Value == t.Value
select new XElement("pic", o.Value)).Distinct());
+1儘管我不得不實施一個不好解決由於時間問題,我期待着測試和了解您的解決方案 - 感謝阿薩夫 – Asaf 2010-09-16 15:22:29