I have a generic query method defined for the Entity Framework as shown below. When I make my call to the API I'm getting back a list with tons of duplicate elements. Why does the .Distinct()
appear to be doing nothing? I want the entire object to be looked at, not just a single property.
internal IHttpActionResult GetCachedDataOrderedBy<TEntity, TResult>(Func<TEntity, TResult> selector, Func<TResult, string> orderby)
where TEntity : class
{
using (var context = new DataModel.LabSOREntities())
return Ok(context.Set<TEntity>()
.AsNoTracking()
.Select(selector)
.OrderBy(orderby)
.Distinct()
.ToArray());
}
and I'm calling it like so:
public IHttpActionResult GetCountries()
{
return GetCachedDataOrderedBy<vw_Location, Country>(r => new Country {
CountryCode = r.Country_Code,
CountryName = r.Country_Name,
RegionCode = r.Region_Code
}, r => r.CountryCode);
}