litedb-org / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.64k stars 1.25k forks source link

Repository pattern not working as expected #1061

Open ju2pom opened 6 years ago

ju2pom commented 6 years ago

repository.Database.GetCollection<Data>("Collection").FindAll().Where(x => x.Latitude.HasValue && x.Latitude.Value > 0 && x.Longitude.HasValue && x.Longitude.Value > 0) Returns some valid rows

repository.Query<Data>("Collection").Include(x => x.Latitude).Include(x => x.Longitude).Where(x => x.Latitude.HasValue && x.Latitude.Value > 0 && x.Longitude.HasValue && x.Longitude.Value > 0) Returns empty result

Longitude and Latitude are of type double?. I'm using LiteDB v4.1.4 Did I misunderstood anything with the repository pattern?

mbdavid commented 6 years ago

Hi @ju2pom, when you run a Where method after FindAll() you are running over Linq2Object (IEnumerable extensions), not by LiteDB.

kosorin commented 5 years ago

I’m also dealing with the same problem. I noticed LiteDB doesn't fully support Nullable type. Ommit HasValue and Value: Where(x => x.Latitude != null && x.Latitude > 0 && x.Longitude != null && x.Longitude> 0) or just Where(x => x.Latitude > 0 && x.Longitude > 0)

mbdavid commented 5 years ago

Hi @kosorin, try new in v5, please. Also, I made support for HasValue and Value properties.