I have this weird problem when filtering products by date. This simple query shows 36 products.
var products = ctx.ComprasAgiles
.Include(x => x.CompraAgilOferentes)
.Include(x => x.EmpresasGanadoras)
.Include(x => x.ProductosSolicitados)
.Where(x => x.FechaCierre > DateTime.Now && x.Estado == "PUBLICADA" )
.OrderBy(x => x.FechaCierre)
.ToList();
But when I query all products and then filter them by date, like this:
var allProducts = ctx.ComprasAgiles
.Include(x => x.CompraAgilOferentes)
.Include(x => x.EmpresasGanadoras)
.Include(x => x.ProductosSolicitados)
.Where(x => x.Estado == "PUBLICADA")
.OrderBy(x => x.FechaCierre)
.ToList();
var allProductsNotExpired = allProducts
.Where(x => x.FechaCierre > DateTime.Now && x.Estado == "PUBLICADA")
.OrderBy(x => x.FechaCierre)
.ToList();
It throws me 48 products. This second query is correct according to my database. The 10 products that are missing have usually about 1 hour left before expiring. So, the query is failing for about 1 hour.
Any ideas about what this could be? I don't really want to add 1 hour of margin to my query...
Thanks in advance!
Code
EDIT 1 - 05-02-2021 :
It seems that adding 3 hours to expire date kind of solves the issue, but yet again. Is this kind of behavior normal? I've never seen it before and I'm quite confused. All tests are taken under the same environment on my local machine so, both querys should return same results, right?
EDIT 2 - 05-02-2021 :
Ok, it seems it is an error of the datetime on my docker container, which is weird because I have set the timezone of my host machine the same as my local timezone. Ill dig about it a little and report back.
EDIT 3 :
The problem was indeed the timezone of my docker that was containing the database. All I had to do is go to my virtual machine and change it with these commands:
docker exec -it {idOfContainer} bash
dpkg-reconfigure tzdata
And voila!
question from:
https://stackoverflow.com/questions/66065573/efcore-3-1-products-missing-when-filtering-by-date 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…