Wednesday, 11 September 2013

How can I use Distinct operator in C# LINQ query

How can I use Distinct operator in C# LINQ query

I would like to select unique EventYear using following code in c# Its
giving duplicate values. my table (EventMasters) structure is (EventYear
(string), EventCode, EventDescription) I want to select unique or distinct
EventYear
public ActionResult EventYearsMenu()
{
var eventyears = storeDB.EventMasters
.Distinct()
.ToList()
.OrderByDescending(c => c.EventYear ==
c.EventYear.Distinct());
return PartialView(eventyears);
}

No comments:

Post a Comment