title: How to map two different datatype fields using Automapper?
body: <p>I am trying to map fields of an object with child collection of source using Automapper through ProjectTo IQueryable as following: </p>
  
  <pre><code>var map2 = cfg.CreateMap&lt;SourceModel, DestinationModel&gt;(); 
  
  map2.ForMember(fieldName, opt =&gt; opt.MapFrom(source =&gt; source.CustomFieldValues.FirstOrDefault(f =&gt; f.Name == fieldName).Value));
  </code></pre>
  
  <p>Models are as following:</p>
  
  <pre><code>public class SourceModel
  {
    public IEnumerable&lt;CustomFieldValue&gt; CustomFieldValues { get; set; }
  }
  
  public class CustomFieldValue
  {
  
      public string Name { get; set; }
      public string Value { get; set; }
  }
  
  public class DestinationModel
  {
      public string _CUSTOM_Test { get; set; }
      public int _CUSTOM_Mynumber { get; set; }
      public DateTime _CUSTOM_mydate { get; set; }
      public bool _CUSTOM_mybool { get; set; }
      public decimal _CUSTOM_numberdec { get; set; }
      public int _CUSTOM_numint { get; set; }
      public int _CUSTOM_numper { get; set; }
      public DateTime _CUSTOM_mydate2 { get; set; }
      public DateTime _CUSTOM_mydate3 { get; set; }
      public DateTime _CUSTOM_mydate4 { get; set; }
      public int _CUSTOM_mynum2 { get; set; }
  }
  </code></pre>
  
  <p>Expected Result:
  As the collection contains only string values but I need to map with different datatypes based on field name.</p>
  
  <p>Actual Result:
  But when I try to apply conversion then queryable throws exception because sql query doesn't support this conversion.</p>