Error with lambda and float fields

1

Whenever I load my lambda, give me this error:

  

System.InvalidOperationException: 'The specified cast from a   materialized 'System.Double' type to the 'System.Single' type is not   valid. '

This only happens with float fields. If I comment the fields and leave only the strings fields, it runs normally. See the class that implements lambda:

public class Autoriza
    {
        InetContext contexto = new InetContext();
        Liberacao liberacao = new Liberacao();
        public IEnumerable<object> getAutoriza()
        {
            var lista = contexto.Liberacoes
                .Join(contexto.ItensLibs, lib => lib.IdOrcamento, itens => itens.IdOrcamento, (lib, itens) => new { lib, itens })
                .Where(a => a.lib.IdOrcamento == a.itens.IdOrcamento)
                .Select(libera => new
                {
                    libera.lib.TipoVenda,
                    libera.lib.Vencimento,
                    libera.lib.Juros,
                    libera.lib.Entrada,
                    libera.lib.Acrescimo,
                    libera.lib.Desconto,
                    libera.lib.Mensagem,
                    libera.lib.DataLib,
                    libera.lib.Vendedor,
                    libera.lib.Cliente,
                    libera.lib.Filial,
                    libera.itens.Produto,
                    libera.itens.Qtde,
                    libera.itens.Unitario,
                    libera.itens.Custo,
                    libera.itens.CustoDiario,
                    libera.itens.UltCondicao,
                    libera.itens.Total
                }).ToList();

            return lista;
        }
    }

This is my domain class Release:

[Table("LIBERACAO")]
    public class Liberacao
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Column("ID_LIBERACAO")]
        public int IdLiberacao { get; set; }
        [Column("FLAG_LIBERACAO")]
        public byte FlagLiberacao { get; set; }
        [Column("ID_ORCAMENTO")]
        public int IdOrcamento { get; set; }
        [Column("ID_VENDEDOR")]
        public int IdVendedor { get; set; }
        [Column("VENDEDOR")]
        public string Vendedor { get; set; }
        [Column("ID_FILIAL")]
        public int IdFilial { get; set; }
        [Column("FILIAL")]
        public string Filial { get; set; }
        [Column("DATALIB")]
        public float DataLib { get; set; }
        [Column("HORALIB")]
        public float HoraLib { get; set; }
        [Column("ID_CLIENTE")]
        public int IdCliente { get; set; }
        [Column("CLIENTE")]
        public string Cliente { get; set; }
        [Column("TIPO_VENDA")]
        public string TipoVenda { get; set; }
        [Column("JUROS")]
        public float Juros { get; set; }
        [Column("DESCONTO")]
        public float Desconto { get; set; }
        [Column("VENCIMENTO")]
        public float Vencimento { get; set; }
        [Column("ACRESCIMO")]
        public float Acrescimo { get; set; }
        [Column("ENTRADA")]
        public float Entrada { get; set; }
        [Column("PRAZO")]
        public float Prazo { get; set; }
        [Column("TOTAL_LIQUIDO")]
        public float TotalLiquido { get; set; }
        [Column("MIN_TOTAL")]
        public float MinTotal { get; set; }
        [Column("USUARIO")]
        public string Usuario { get; set; }
        [Column("CUSTODIARIO")]
        public decimal CustoDiario { get; set; }
        [Column("MAX_COMI")]
        public decimal MaxComi { get; set; }
        [Column("VALOR_COMI")]
        public decimal ValorComi { get; set; }
        [Column("NOVA_COMI")]
        public decimal NovaComi { get; set; }
        [Column("MENSSAGEM")]
        public string Mensagem { get; set; }
        [Column("Menssagem_RET")]
        public string MensagemRet { get; set; }
        [Column("DataRetorno")]
        public decimal DataRetorno { get; set; }
        [Column("HoraRetorno")]
        public decimal HoraRetorno { get; set; }
        [Column("TempoProcesso")]
        public decimal TempoPrecesso { get; set; }
        [Column("Tipo")]
        public int Tipo { get; set; }
        [Column("PROGRAMA")]
        public string Programa { get; set; }
        [Column("NOME_PC")]
        public string NomePc { get; set; }
        [Column("NOME_PROCEDURE")]
        public string NomeProcedure { get; set; }
        [Column("Perc_Juros_Total")]
        public decimal PercJurosTotal { get; set; }
        [Column("FLAG_CULTURAVENCIDA")]
        public byte FlagCulturaVencida { get; set; }
        [Column("CULTURA")]
        public string Cultura { get; set; }
        [Column("CULTURA_VCTO")]
        public int CulturaVcto { get; set; }
        [Column("FLAG_PRORROGADO")]
        public byte FlagProrrogado { get; set; }
        [Column("VALOR_PRORROGADO")]
        public decimal ValorProrrogado { get; set; }
        [Column("DIAS_ATRASO")]
        public int DiasAtrazo { get; set; }
        [Column("ID_VENDEDOR2")]
        public int IdVendedor2 { get; set; }
        [Column("VENDEDOR2")]
        public string Vendedor2 { get; set; }
        [Column("COMISSAO_VEND2")]
        public decimal ComissaoVend2 { get; set; }
        [Column("FLAG_COTACAO")]
        public byte FlagCotacao { get; set; }
        [Column("TipoVenda")]
        public string TipoVenda1 { get; set; }
        [Column("Flag_Receber_Atrasado")]
        public byte FlagReceberAtrazado { get; set; }
        [Column("Autorizou_Receber_Atrasado")]
        public string AutorizouReceberAtrazado { get; set; }

    }

and the ITENSLIB domain class

[Table("ITENSLIB")]
    public class ItensLib
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Column("ID_ITENSLIB")]
        public int IdItensLib { get; set; }
        [Column("ID_ORCAMENTO")]
        public int IdOrcamento { get; set; }
        [Column("ID_PRODUTO")]        
        public int IdProduto { get; set; }
        [Column("PRODUTO")]
        public string Produto { get; set; }
        [Column("QTDE")]
        public float Qtde { get; set; }
        [Column("UNITARIO")]
        public float Unitario { get; set; }
        [Column("CUSTO")]
        public float Custo { get; set; }
        [Column("MINIMO")]
        public float Minimo { get; set; }
        [Column("TOTAL")]
        public float Total { get; set; }
        [Column("CUSTODIARIO")]
        public decimal CustoDiario { get; set; }
        [Column("FABRICANTE")]
        public string Fabricante { get; set; }
        [Column("ULT_CONDICAO")]
        public decimal UltCondicao { get; set; }
        [Column("PROGRAMA")]
        public string Programa { get; set; }
        [Column("NOME_PC")]
        public string NomePc { get; set; }
        [Column("NOME_PROCEDURE")]
        public string NomeProcedure { get; set; }
        [Column("Flag_Vencido")]
        public byte FlagVencido { get; set; }
        [Column("TipoVenda")]
        public string TipoVenda { get; set; }
        [Column("VENDA_VISTA")]
        public float VendaVista { get; set; }
        [Column("MARGEM_AVISTA")]
        public float MargemAvista { get; set; }
        [Column("QTDE_NEG_AVISTA")]
        public float QtdNegAvista { get; set; }
        [Column("VENDA_PRAZO")]
        public float VendaPrazo { get; set; }
        [Column("PM_PRAZO")]
        public float PmPrazo { get; set; }
        [Column("MARGEM_PRAZO")]
        public float MargemPrazo { get; set; }
        [Column("JUROS_PRAZO")]
        public float JurosPrazo { get; set; }
        [Column("QTDE_PRAZO")]
        public float QtdePrazo { get; set; }
        [Column("VENDA_VISTA_ANT")]
        public float VendaVistaAnt { get; set; }
        [Column("MARGEM_AVISTA_ANT")]
        public float MargemAvistaAnt { get; set; }
        [Column("QTDE_NEG_AVISTA_ANT")]
        public float QtdeNegAvistaAnt { get; set; }
        [Column("VENDA_PRAZO_ANT")]
        public float VendaPrazoAnt { get; set; }
        [Column("PM_PRAZO_ANT")]
        public float PmPrazoAnt { get; set; }
        [Column("MARGEM_PRAZO_ANT")]
        public float MargemPrazoAnt { get; set; }
        [Column("JUROS_PRAZO_ANT")]
        public float JurosPrazoAnt { get; set; }
        [Column("QTDE_PRAZO_ANT")]
        public float QtdePrazoAnt { get; set; }
        [Column("VENDA_VISTA_ANT1")]
        public float VendaVistaAnt1 { get; set; }
        [Column("MARGEM_AVISTA_ANT1")]
        public float MargemAvistaAnt1 { get; set; }
        [Column("QTDE_NEG_AVISTA_ANT1")]
        public float QtdeNegAvistaAnt1 { get; set; }
        [Column("VENDA_PRAZO_ANT1")]
        public float VendaPrazoAnt1 { get; set; }
        [Column("PM_PRAZO_ANT1")]
        public float PmPrazoAnt1 { get; set; }
        [Column("MARGEM_PRAZO_ANT1")]
        public float MargemPrazoAnt1 { get; set; }
        [Column("JUROS_PRAZO_ANT1")]
        public float JurosPrazoAnt1 { get; set; }
        [Column("QTDE_PRAZO_ANT1")]
        public float QtdePrazoAnt1 { get; set; }
    }

And my controller, where I call my m, odel running lambda

 public class AutorizaController : ApiController
    {
        Autoriza autoriza = new Autoriza();

        [AcceptVerbs("Get")]
        public IEnumerable<object> getLiberacao()
        {
            return autoriza.getAutoriza().ToList();
        }
    }

This is the Release table with the fields coming in the model. I only put the Release, because I did a test with only her fields and continues with the same error.

    
asked by anonymous 23.08.2017 / 15:14

1 answer

1

Fields of type REAL can not be represented by decimal , they are floating-point numbers and therefore must be represented by a double field or even float .

I based my answer on what was said in the comments (transcript below - highlighted by me) because the question did not have this information.

  

" (...) I put the same types of fields, except for the REAL fields in the database, which in my class I changed to decimal "

>
    
23.08.2017 / 15:49