Service returns cast error when consumed

5

I decided to make another post, since the subject is another, although in the original post, in the comments we get to touch on the subject, but without depth. I have this error:

  

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

I did not understand the error, since in the bank I have the same types as in the application. The difference is that I threw in the application the float and decimal fields, I did accept null , as it is in the database. Below my Entity Class Model:

[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 double? DataRetorno { get; set; }
        [Column("HoraRetorno")]
        public double? HoraRetorno { get; set; }
        [Column("TempoProcesso")]
        public double? 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 double? 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 double? 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; }
    }

Following the guidelines of colleague Gabriel (another post), I created a LiberacaoDTO class, but I just created the class with that name. I do not know if I should do something else, to understand that it's not just a name, but a real DTO. I'm not sure if I did it right or not. Below the class:

public class LiberacaoDTO
    {
        public int IdLiberacao { get; set; }
        public byte FlagLiberacao { get; set; }
        public int IdOrcamento { get; set; }
        public int IdVendedor { get; set; }
        public string Vendedor { get; set; }
        public int IdFilial { get; set; }
        public string Filial { get; set; }
        public float? DataLib { get; set; }
        public float? HoraLib { get; set; }
        public int IdCliente { get; set; }
        public string Cliente { get; set; }
        public string TipoVenda { get; set; }
        public float? Juros { get; set; }
        public float? Desconto { get; set; }
        public float? Vencimento { get; set; } 
        public float? Acrescimo { get; set; }
        public float? Entrada { get; set; }
        public float? Prazo { get; set; }
        public float? TotalLiquido { get; set; }
        public float? MinTotal { get; set; }
        public string Usuario { get; set; }
        public decimal? CustoDiario { get; set; }
        public decimal? MaxComi { get; set; }
        public decimal? ValorComi { get; set; }
        public decimal? NovaComi { get; set; }
        public string Mensagem { get; set; }
        public string MensagemRet { get; set; }
        public double? DataRetorno { get; set; }
        public double? HoraRetorno { get; set; }
        public double? TempoPrecesso { get; set; }
        public int Tipo { get; set; }
        public string Programa { get; set; }
        public string NomePc { get; set; }
        public string NomeProcedure { get; set; }
        public decimal? PercJurosTotal { get; set; }
        public byte FlagCulturaVencida { get; set; }
        public string Cultura { get; set; }
        public int CulturaVcto { get; set; }
        public byte FlagProrrogado { get; set; }
        public double? ValorProrrogado { get; set; }
        public int DiasAtrazo { get; set; }
        public int IdVendedor2 { get; set; }
        public string Vendedor2 { get; set; }
        public double? ComissaoVend2 { get; set; }
        public byte FlagCotacao { get; set; }
        public string TipoVenda1 { get; set; }
        public byte FlagReceberAtrazado { get; set; }
        public string AutorizouReceberAtrazado { get; set; }
    }

The method that populates the DTO and returns a list for the service:

public class PedidoLiberacao
    {
        AutorizadorContext contexto = new AutorizadorContext();
        Liberacao liberacao = new Liberacao();

        public List<LiberacaoDTO> getAutoriza(int idorcamento)
        {
            var lista = contexto.Liberacoes
                        .Where(lib => lib.IdOrcamento == idorcamento)
                        .Select(lib => new LiberacaoDTO
                        {
                            TipoVenda = lib.TipoVenda,
                            Vencimento = lib.Vencimento,
                            Juros = lib.Juros,
                            Entrada = lib.Entrada,
                            Acrescimo = lib.Acrescimo,
                            Desconto = lib.Desconto,
                            Mensagem = lib.Mensagem,
                            DataLib = lib.DataLib,
                            Vendedor = lib.Vendedor,
                            Cliente = lib.Cliente,
                            Filial = lib.Filial
                        }).ToList();

            return lista;
        }
    }

Here is my service that takes the return method above:

public class LiberacaoController : ApiController
    {
        AutorizadorContext contexto = new AutorizadorContext();
        PedidoLiberacao liberacao = new PedidoLiberacao();

        [AcceptVerbs("Get")]
        public IEnumerable<LiberacaoDTO> getLiberacao()
        {
            return liberacao.getAutoriza(1000012093).AsEnumerable().ToList();
            //return contexto.Liberacoes.AsEnumerable().ToList();
         }
    }

Below my sql server and the database and the fields listed (some as a matter of space)

The question is: if I'm in the way, why the above error?

This is the error trace stack

  

in   System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader 1.GetValue(DbDataReader reader, Int32 ordinal) em lambda_method(Closure , Shaper ) em System.Data.Entity.Core.Common.Internal.Materialization.Coordinator 1.ReadNextElement (Shaper   shaper) in   System.Data.Entity.Core.Common.Internal.Materialization.Shaper 1.SimpleEnumerator.MoveNext() em System.Data.Entity.Internal.LazyEnumerator 1.MoveNext () in   System.Collections.Generic.List 1..ctor(IEnumerable 1 collection)
  in System.Linq.Enumerable.ToList [TSource] (IEnumerable 1 source) em AutorizadorService.Controllers.LiberacaoController.getLiberacao() na C:\Projetos\AutorizadorService\AutorizadorService\Controllers\LiberacaoController.cs:linha 22 em lambda_method(Closure , Object , Object[] ) em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) em System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary 2 arguments, CancellationToken   cancellationToken)

    
asked by anonymous 25.08.2017 / 15:14

0 answers