I have a performance question, how entity framework binding of values can affect performance?
Im making a few tests on LINQPad and this code runs extremely fast, and generates a fast query if run directly on the database...
var dataFim = new DateTime(2015,12,12);
var dataInicio = new DateTime(2015,01,01);
long? empresaClienteId = 1081;
var query = Transacoes
.Select(t => new { t.Data, t.Estorno, t.EmpresaClienteId, t.KmFinal, t.KmInicial, t.ValorBruto})
.Where(t => t.Data.Value >= dataInicio
&& t.Data.Value < dataFim
&& t.Estorno == "N"
&& t.EmpresaClienteId == empresaClienteId
&& (t.KmFinal - t.KmInicial) < 500)
.GroupBy(t => new { t.Data.Value.Month, t.Data.Value.Year })
.OrderBy(t => new { t.Key.Month, t.Key.Year })
.Select(t => new
{
Mes = t.Key.Month,
Ano = t.Key.Year,
ValorTotal = t.Sum(r => r.ValorBruto ?? 0),
KmPercorridoTotal = t.Sum(r => (r.KmFinal ?? 0) - (r.KmInicial ?? 0))
});
query.AsNoTracking().Dump();
... But, If I change this variable to var
var empresaClienteId = 1081;
or long
long empresaClienteId = 1081;
Then suddenly the query takes forever (but not if running direclty on the database)
both the model and the request parameter are non nullable longs, and so is the storage column mapping.
Any Ideas why this happens and how to handle this? Having the long? variable is not desirable since thats a non nullable parameter
PS: Im using Oracle Database and devart