I am trying to use AutoMapper 3 to project a class using the Integer property into another class with the String property.
When the request is executed, I get the following exception:
System.NotSupportedException: LINQ to Entities does not recognize the 'System.String ToString ()' method, and this method cannot be translated into a storage expression.
Here are the relevant parts of the code:
public partial class Lookup
{
public int LookupId { get; set; }
public int LookupTypeId { get; set; }
public string Value { get; set; }
public int SequencialOrder { get; set; }
public virtual LookupType LookupType { get; set; }
}
public class LookupProfile : Profile
{
protected override void Configure()
{
CreateMap<Lookup, SelectListItem>()
.ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.LookupId.ToString()))
.ForMember(dest => dest.Text, opt => opt.MapFrom(src => src.Value));
}
}
And the request looks like this:
Provinces = _db.Lookups.Project().To<SelectListItem>().ToList()
Question:
Is there a way to configure LookupProfile to display correctly and still work inside Linq To Entities? Or is there another way to get a projection to work with Linq in Entities?