我需要在LINQ
的一列上使用distinct
檢索整個行集合。LINQ中的一列上使用不同的整行LINK
我得到Distinct
使用GroupBy
但它只選擇一列值,而我需要整行。
**此列表返回ThumbnailAltText列中唯一的集合,但BUT只返回該列而不是整個行值。所以我只好用var
代替type
var catlist = _db.ac_Categories
.Where(c => c.VisibilityId == 0 && c.ThumbnailAltText != null
&& (!c.ThumbnailAltText.StartsWith("gifts/")
&& !c.ThumbnailAltText.StartsWith("email/")
&& !c.ThumbnailAltText.StartsWith("news/")
&& !c.ThumbnailAltText.StartsWith("promotions/")
&& !c.ThumbnailAltText.StartsWith("the-knowledge/"))).ToList()
.GroupBy(c=> c.ThumbnailAltText.Trim().Distinct()).ToList();
.GroupBy(c=> c.ThumbnailAltText.Trim().Distinct()).ToList();
同樣的事情不會type
喜歡這個工作,我收到錯誤。
List<ac_Categories> catlist = _db.ac_Categories
.Where(c => c.VisibilityId == 0 && c.ThumbnailAltText != null
&& (!c.ThumbnailAltText.StartsWith("gifts/")
&& !c.ThumbnailAltText.StartsWith("email/")
&& !c.ThumbnailAltText.StartsWith("news/")
&& !c.ThumbnailAltText.StartsWith("promotions/")
&& !c.ThumbnailAltText.StartsWith("the-knowledge/"))).ToList()
.GroupBy(c=> c.ThumbnailAltText.Trim().Distinct()).ToList();
.GroupBy(c=> c.ThumbnailAltText.Trim().Distinct()).ToList();
錯誤:The 'Distinct' operation cannot be applied to the collection ResultType of the specified argument.
編輯:我需要一個集合,而不是第一個記錄,ID等欄目包含差異值僅ThumbnailAltText我包含重複
你能否提供ac_Categories類型定義 – zabulus
它的一個實體使用數據庫的第一種方法創建...它的一個非常大的表,所以不能在這裏提供... –