I just stuck up with the issue, i am fetching data from database using entity framework, but facing problems.
Problem
My Role table has multiple Roles, it contains duplicate values like others 4 times, i am fetching it and binding it to dropdown, but i am getting others value 4 times in dropdown list
Here is the code that i am trying.
public List<RefrenceDataModel> GetJobRoles()
{
List<RefrenceDataModel> lstRefrenceDataReturn = new List<RefrenceDataModel>();
DataContext context = new DataContext();
lstRefrenceDataReturn = context.JobsRoles.ToList().distinct().Select(items => new RefrenceDataModel() { RefrenceDataName = items.RoleName, RefrenceDataID = items.RoleID }).ToList<RefrenceDataModel>();
return lstRefrenceDataReturn;
}
This code is returning duplicate values, but i don't want duplicates, what i am doing wrong?
Distinct(your implementation of IEqualityComparer<T>)RefrenceDataModeltype does not implementIEquatable<RefrenceDataModel>properly or at all. (And as a side note, isRefrenceDataModelspelt right? ;))