Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

c# - EFCore 3.1 Products missing when filtering by date

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...