Separate statement in List <string>
3 answers
If, for example, BatchRouteId was an XElement , it might be possible to compare object references. In this case, change the code to
var ret = context.XInventTransBackOrder .Where(i => i.BatchRouteId != null && !String.IsNullOrEmpty(i.BatchRouteId.Value)) .Select(i => i.BatchRouteId.Value) .Distinct() .ToList(); UPDATE # 1
Note that some types implement implicit conversions, making you think they were a different type. You can pass the string parameter to XName without casting explicitly, and string will be automatically converted to XName .
UPDATE # 2
According to nk2003dec comment, LinqToDynamicsAx context. I do not know this interface, but it probably does not implement Distinct . In this case, you can change the context form of XY-LINQ to Object-LINQ using the extension method System.Linq.Enumerable.AsEnumerable<TSource>
var ret = context.XInventTransBackOrder .Select(i => i.BatchRouteId) .Where(id => id != "") .AsEnumerable() .Distinct() .ToList(); I also inverted Select and Where , as this simplifies access to BatchRouteId
+3