Remove duplicates in the list using linq
var distinctItems = items.GroupBy(x => x.Id).Select(y => y.First());
var distinctItems = items.GroupBy(x => x.Id).Select(y => y.First());
Just stumbled into this oldie… To do this without the dynamic LINQ library, you just need the code as below. This covers most common scenarios including nested properties. To get it working with IEnumerable<T> you could add some wrapper methods that go via AsQueryable – but the code below is the core Expression logic needed. … Read more
If you want to “remove” the property you will have create new type without this property: oList = db.Categories.Select(p => new YourNewCategorySml { CategoryName = p.CategoryName }) .ToList(); or use the anonymous type: oList = db.Categories.Select(p => new { CategoryName = p.CategoryName }) .ToList();