Cast to decimal in LINQ?

1

Since there is no Convert.ToDecimal() in SQL language, how could I transcribe a as decimal(18,2) in LINQ ?

I've tried through decimal.Round() but it's not working.

I have the following query in SQL :

SELECT 
[nu_ano],
[nu_mes],
[id_projeto],
[id_fase],
'Financial Progress ("Competência")' as ds_categoria,
'Baseline' as ds_curva,
vl_baseline as vl_curva,
cast((vl_baseline / (pc_baseline / 100)) as decimal(18,2)) as vl_curva_total
FROM [Alvarez_Marsal].[dbo].[Schedule_Status]

And my query in LINQ is like this

var result = (from l in db.Schedule_Status
        .Where(x => x.nu_mes == 12)
            .Select(x => new Retorno
            {
            nu_ano = x.nu_ano,
            nu_mes = x.nu_mes,
            id_projeto = x.id_projeto,
            id_fase = x.id_fase,
            ds_categoria = "Financial Progress ('Competência')",
            ds_curva = "Baseline",
            vl_curva = x.vl_baseline,
            vl_curva_total = decimal.Round((decimal)((x.vl_baseline / (x.pc_baseline / 100)), 2)
            })
        select l);

Turning my query LINQ into SQL looks like this:

SELECT 
[Extent1].[nu_ano] AS [nu_ano], 
[Extent1].[nu_mes] AS [nu_mes], 
[Extent1].[id_projeto] AS [id_projeto], 
[Extent1].[id_fase] AS [id_fase], 
N'Financial Progress (''Competência'')' AS [C1], 
N'Baseline' AS [C2], 
[Extent1].[vl_baseline] AS [vl_baseline], 
ROUND(([Extent1].[vl_baseline] / [Extent1].[pc_baseline]) / cast(100 as decimal(18)), 2) AS [C3]
FROM [dbo].[Schedule_Status] AS [Extent1]
WHERE 12 = [Extent1].[nu_mes]

The vl_curva_total field in my query LINQ is returning 3000.0000000000000000000 while the right is to return 30000000.00

    
asked by anonymous 26.04.2018 / 21:04

0 answers