title: The specified cast from a materialized 'System.Double' type to the 'System.Single' type is not valid. Can I solve this error
body: <p>I have a DTO class in my project. So, when I run in run time I have this message:</p>
  
  <blockquote>
    <p>The specified cast from a materialized 'System.Double' type to the
    'System.Single' type is not valid.</p>
  </blockquote>
  
  <p>This message appear when I put float or double type only. I mapped my DTO class, but the error continue. With decimal or int work fine. This is my DTO class:</p>
  
  <pre><code>public class LiberacaoItensDTO
      {
          public LiberacaoItensDTO()
          {
              Mapper.Initialize(cfg =&gt;
              {
                  cfg.CreateMap&lt;LiberacaoItensDTO, Liberacao&gt;()
                  .ForMember(d =&gt; d.DataLib, opt =&gt; opt.MapFrom(src =&gt; Convert.ToDateTime(DataLib)));
                  cfg.CreateMap&lt;LiberacaoItensDTO, Liberacao&gt;()
                  .ForMember(d =&gt; d.Juros, opt =&gt; opt.MapFrom(src =&gt; Juros.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, Liberacao&gt;()
                  .ForMember(d =&gt; d.Desconto, opt =&gt; opt.MapFrom(src =&gt; Desconto.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, Liberacao&gt;()
                  .ForMember(d =&gt; d.Acrescimo, opt =&gt; opt.MapFrom(src =&gt; Acrescimo.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, Liberacao&gt;()
                 .ForMember(d =&gt; d.Vencimento, opt =&gt; opt.MapFrom(src =&gt; Convert.ToDateTime(Vencimento)));
                  cfg.CreateMap&lt;LiberacaoItensDTO, Liberacao&gt;()
                  .ForMember(d =&gt; d.Entrada, opt =&gt; opt.MapFrom(src =&gt; Entrada.ToString("C2")));
  
                  cfg.CreateMap&lt;LiberacaoItensDTO, ItensLib&gt;()
                  .ForMember(d =&gt; d.Qtde, opt =&gt; opt.MapFrom(src =&gt; Qtde.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, ItensLib&gt;()
                  .ForMember(d =&gt; d.Unitario, opt =&gt; opt.MapFrom(src =&gt; Unitario.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, ItensLib&gt;()
                  .ForMember(d =&gt; d.Custo, opt =&gt; opt.MapFrom(src =&gt; Custo.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, ItensLib&gt;()
                  .ForMember(d =&gt; d.CustoDiario, opt =&gt; opt.MapFrom(src =&gt; CustoDiario.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, ItensLib&gt;()
                  .ForMember(d =&gt; d.UltCondicao, opt =&gt; opt.MapFrom(src =&gt; UltCondicao.ToString("C2")));
                  cfg.CreateMap&lt;LiberacaoItensDTO, ItensLib&gt;()
                  .ForMember(d =&gt; d.Total, opt =&gt; opt.MapFrom(src =&gt; Total.ToString("C2")));
              });
          }
          public int IdLiberacao { get; set; }
          [DefaultValue(0)]
          public int IdOrcamento { get; set; }
          [DefaultValue(0)]
          public int IdVendedor { get; set; }
          public string Vendedor { get; set; }
          public int IdFilial { get; set; }
          public string Filial { get; set; }
          [DefaultValue(0)]
          public float DataLib { get; set; }
          public int IdCliente { get; set; }
          public string Cliente { get; set; }
          public string TipoVenda { get; set; }
          [DefaultValue(0)]
          public float Juros { get; set; }
          [DefaultValue(0)]
          public float Desconto { get; set; }
          [DefaultValue(0)]
          public float Vencimento { get; set; }
          [DefaultValue(0)]
          public float Acrescimo { get; set; }
          [DefaultValue(0)]
          public float Entrada { get; set; }
          public string Mensagem { get; set; }
          public int IdProduto { get; set; }
          public string Produto { get; set; }
          [DefaultValue(0)]
          public float Qtde { get; set; }
          [DefaultValue(0)]
          public float Unitario { get; set; }
          [DefaultValue(0)]
          public float Custo { get; set; }
          [DefaultValue(0)]
          public float CustoDiario { get; set; }
          [DefaultValue(0)]
          public float UltCondicao { get; set; }
          [DefaultValue(0)]
          public float Total { get; set; }
      }
  </code></pre>
  
  <p>below my method. This method return a DTO object type:</p>
  
  <pre><code>public List&lt;LiberacaoItensDTO&gt; getAutoriza(int idorcamento)
          {
  
              var lista = contexto.Liberacoes
                          //.Where(lib =&gt; lib.IdOrcamento == idorcamento)
                          .Join(contexto.ItensLibs, lib =&gt; lib.IdOrcamento, itens =&gt; itens.IdOrcamento, (lib,itens) =&gt; new { lib, itens})
                          .Where(a =&gt; a.lib.IdOrcamento == a.itens.IdOrcamento &amp;&amp; a.lib.IdOrcamento == idorcamento)
                          .Select(libera =&gt; new LiberacaoItensDTO
                          {
                              TipoVenda = libera.lib.TipoVenda,
                              IdOrcamento = libera.lib.IdOrcamento,
                              Juros = libera.lib.Juros != 0 ? libera.lib.Juros : 0,
                              //Entrada = libera.lib.Entrada != 0 ? libera.lib.Entrada : 0,
                              //Acrescimo = libera.lib.Acrescimo != 0 ? libera.lib.Acrescimo : 0,
                              //Desconto = libera.lib.Desconto != 0 ? libera.lib.Desconto : 0,
                              Mensagem = libera.lib.Mensagem,
                              //DataLib = libera.lib.DataLib != 0 ? libera.lib.DataLib : 0,
                              Qtde = libera.itens.Qtde != 0 ? libera.itens.Qtde : 0,
                              Vendedor = libera.lib.Vendedor,
                              Cliente = libera.lib.Cliente,
                              Filial = libera.lib.Filial
                          }).ToList();
              return lista;
          }
  </code></pre>
  
  <p>And my rest service:</p>
  
  <pre><code>public class LiberacaoController : ApiController
      {
          AutorizadorContext contexto = new AutorizadorContext();
          PedidoLiberacao liberacao = new PedidoLiberacao();
  
          [AcceptVerbs("Get")]
          public IEnumerable&lt;LiberacaoItensDTO&gt; getLiberacao()
          {
              return liberacao.getAutoriza(1000012093).AsEnumerable().ToList();
          }
      }
  </code></pre>
  
  <p>If I comment this line <code>Juros = libera.lib.Juros != 0 ? libera.lib.Juros : 0,</code> or other with float field, work fine. Otherwise not.</p>