I have a parent class:
public class Parent
{
...
public List<Location> Locations { get; set; }
}
Location class:
public class Location
{
public int LocationId { get; set; }
public string Name { get; set; }
}
Destination class for mapping:
public class Destination
{
...
public string DelimitedLocations { get; set; }
}
I need to map the LocationId list from Locations to a comma delimited string using automapper.
Here are several things I have tried:
CreateMap<Parent, Destination>().ForMember(d => d.DelimitedLocations , o => o.MapFrom(s => string.Join(",", s.Locations.ToList().Select(t => t.LocationID.ToString()))))
Result: LINQ to Entities does not recognize the method 'System.String Join(System.String, System.Collections.Generic.IEnumerable`1[System.String])' method, and this method cannot be translated into a store expression.
Next attempt:
CreateMap<Parent, Destination>()..ForMember(d => d.TestPlotLocationsSelected, o => o.MapFrom(s => s.TestPlotLocations.ToList().Select(t => string.Join(",", t.TestPlotLocationID.ToString()))))
Result: No method 'ToString' exists on type 'System.Collections.Generic.IEnumerable`1[System.String]'.
Not sure what to try next.

set;of yourDelimitedLocations, you could try to just create aStringBuilderand aforeachand ultimately create what you want - that may be a lot easier.. - Mark C.