C# - Comparison of date with LINQ does not bring the expected result

Asked

Viewed 39 times

0

We have an Oracle database with a View.

We have to take the total harvested cane by adding the column QT_LIQUIDO according to the day.

We made the code in C#, but it is with an unexpected behavior.

If we do the direct date comparison in dbContext it works out and it does the sum of the value.

But if we already call dbContext the sum result is always 0.

Note the code used below:

//Data que vem no body do POST (30/04/2018)
DateTime data_filtro = Convert.ToDateTime(filtros.data);

//Filtrando a safra direto no banco
var cana = _db.DbCanaTotal.Where(u => u.CD_SAFRA.Equals(Convert.ToInt32(filtros.safra))); 

//A partir do filtro de safra um IEnumerable (DÁ ZERO A SOMA)
dto.dia = cana.Where(r => r.DT_MOVIMENTO.Equals(data_filtro)).Sum(r => r.QT_LIQUIDO);

//Direto do banco (DÁ CERTO A SOMA COM o WHERE IGUAL AO DE CIMA)
dto.dia = _db.DbCanaTotal.Where(u => u.DT_MOVIMENTO.Equals(data_filtro)).Sum(x => x.QT_LIQUIDO); 

My friend and I don’t know what else to do

  • you test like this: _db.DbCanaTotal.Where(u => u.DT_MOVIMENTO == data_filtro) and tell me the result! don’t use Equals has different behavior... !!! I have used ==

  • and check your records and filters, 2019-04-17 22:06:35:345 is different from 2019-04-17 00:00:000

  • @Witnesstruth Made his move?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.