【发布时间】:2013-10-17 09:10:40
【问题描述】:
我需要在LINQ 的一列上使用distinct 检索整个行集合。
我正在使用GroupBy 获取Distinct,但它只选择一列值而不是我需要整行。
**此列表返回在 ThumbnailAltText 列中唯一的集合,但仅返回该列而不是整行值。所以我不得不使用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类型定义
-
它是使用数据库优先方法创建的实体...它是一个非常大的表,因此无法在此处提供...