mbdavid / LiteDB

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

Expression Query result is error [BUG] #2408

Open stanlylee opened 10 months ago

stanlylee commented 10 months ago

Version latest

Describe the bug document:

    public class Customer
    {
        public class Contact
        {
            public string Phone           { get; set; }
            public String email           { get; set; }
            public int id { get; set; }
        }
        [LiteDB.BsonId]
        public Int64 dataid               { get; set; }
        public string Name                { get; set; }
        public int Age                    { get; set; }
        public List<Contact> contacts     { get; set; }    
        public bool IsActive              { get; set; }
    }

data:

static Int64 Insert(String name , String phone , String email , int age , int id , ILiteCollection<Customer> col);
Insert("Person1", "8000-0001", "0001@qq.com" , 99, 11  , col);
Insert("Person2", "8000-0002", "0002@qq.com" , 39, 22  , col);
Insert("Person3", "8000-0003", "0003@qq.com" , 19 , 43 , col);
Insert("Person4", "8000-0004", "0004@qq.com" , 49 , 14 , col);
Insert("Person5", "8000-0005", "0005@qq.com" , 35 , 35 , col);

query step:

                List<int> Ids5 = new List<int>() { 22, 43, 14 };
                var find5 = col.Find(x => x.contacts.Select(c => Ids5.Contains(c.id)).Any(t => t == true)).ToList();
                db.Rebuild();

                List<int> Ids4 = new List<int>() { 22 };
                var find4  = col.Find(x => x.contacts.Select(c => Ids4.Contains( c.id) ).Any( t => t == true  )).ToList();

find5' is correct , have 3 elements. find4's should be only one customer named "Person2" , but have 3 elements.

I have trace the source code . if disable BsonExpresssion ’s BsonExpressionScalarDelegate cache and BsonExpressionEnumerableDelegate cache . compile the expression every time . the result will be correct

Code to Reproduce Every time

stanlylee commented 10 months ago

BsonExpression.zip Modified BsonExpression.cs