Distinct operator on List<string>

nk2003dec picture nk2003dec · Nov 26, 2012 · Viewed 14.9k times · Source

I'm trying to get distinct string values out of an Ax repository, but I'm getting a lot of identical strings out (strings only contains numbers)

var ret = context.XInventTransBackOrder
    .Where(i => i.BatchRouteId != "")
    .Select(i => i.BatchRouteId)
    .Distinct()
    .ToList();

Where am I going wrong?

Answer

Jan Lund Madsen picture Jan Lund Madsen · Nov 26, 2012

Have you tried

var ret = context.XInventTransBackOrder
    .Where(i => i.BatchRouteId != "")
    .Select(i => i.BatchRouteId)
    .ToList();
ret = ret
    .Distinct()
    .ToList();