I need to retrieve the entire rows collection using distinct
on one column in LINQ
.
i am getting the Distinct
using GroupBy
but it only selects the one column values instead i need entire row.
**this list returns the collection which is unique in ThumbnailAltText column BUT only returns that column rather than entire row values. so i had to use var
instead of 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();
same thing does not work with type
like this and i am getting error.
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();
ERROR: The 'Distinct' operation cannot be applied to the collection ResultType of the specified argument.
EDIT: I need a collection and not the first record, ID and other columns contains diff values only ThumbnailAltText my contain duplicates