1
A
回答
0
您可以通過實現IEqualityComparer<TSource>
接口來創建一個相等比較器。然後你通過ConcreteEqualityComparer
到Distinct()
:
Selections.Distinct(new ConcreteEqualityComparer());
0
你需要實現IEqualityComparer<T>
0
的IEqualityComparer sample implementation。無恥link以我的答案爲一個類似的SO問題
0
您也可以重寫您試圖過濾的實例類的方法Equals和GetHashCode方法。
相關問題
- 1. LINQ GroupBy和Distinct
- 2. C#LINQ Distinct和ADO.NET EF
- 3. LINQ中的orderby()和distinct()
- 4. LINQ的:SELECT DISTINCT和秩序
- 5. LINQ Union and Distinct
- 6. 幫助LINQ distinct()
- 7. Linq to entities:Unions + Distinct
- 8. Linq to Entities Distinct Clause
- 9. Linq to Entities Select Distinct
- 10. Linq To Entities Optional Distinct
- 11. LINQ返回DISTINCT值
- 12. IEqualityComparer和Linq Distinct - 硬代碼GetHashCode()
- 13. Linq鏈接SELECT和DISTINCT運算符
- 14. vb.net LINQ SELECT DISTINCT到列表
- 15. linq&distinct,執行equals&gethashcode
- 16. Linq Group By or Distinct with Join
- 17. LINQ - SELECT DISTINCT與NOT IN
- 18. LINQ數據表SELECT DISTINCT行
- 19. LINQ to Entities - DISTINCT在一列
- 20. LINQ選擇列表與DISTINCT
- 21. Linq to DataTable not produced Distinct values
- 22. LINQ到SQL:SELECT最新DISTINCT項
- 23. LINQ到對象 - SELECT DISTINCT
- 24. DISTINCT()和ORDERBY問題
- 25. why.ToList()。Distinct()拋出錯誤但不是.Distinct()。ToList()with linq查詢
- 26. DISTINCT和ORDER
- 27. C#LINQ Distinct(f => f.propertyname)does not work
- 28. 帶有DISTINCT的C#LINQ計數元素
- 29. C#LINQ Lambda query with select,Where,Count and Distinct
- 30. LINQ SELECT DISTINCT在評價多行
如果他使用LINQ to SQL(這是他如何標記的,儘管他的代碼看起來更像是LINQ to Objects),在這種情況下,這是行不通的,因爲相等比較器不能轉換爲SQL。 (當然,它將在LINQ to Objects中工作。) – itowlson 2009-12-12 01:02:15