2012-07-13 29 views
0

我有一個數據集,並使用下面的查詢中的DataSet從表中選擇幾個記錄:檢索重複的記錄在LINQ查詢

EnumerableRowCollection<DataRow> GenresQuery = from genre in Books.AsEnumerable() where genre.Field<string>("genre") == strGenresSelectionParameter select genre;

它工作正常,但,我要選擇不重複的記錄。如何做到這一點?

+0

選擇什麼記錄?這裏沒有足夠的信息讓我們知道你在說什麼。該代碼無效,查詢的類型爲'IEnumerable ',而不是你在那裏的。 – 2012-07-13 06:15:35

回答

1

使用Distinct

IEnumerable<DataRow> GenresQuery = (from genre in Books.AsEnumerable() 
            where genre.Field<string>("genre") == strGenresSelectionParameter 
            select genre).Distinct(); 
+0

得到此錯誤:**不能將類型'System.Collections.Generic.IEnumerable '隱式轉換爲'System.Data.EnumerableRowCollection '。存在明確的轉換(您是否缺少演員?)** – 2012-07-13 06:23:44

+0

您需要將結果分配給'IEnumerable '而不是'EnumerableRowCollection' – Habib 2012-07-13 06:24:51