You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using LiteDB;
var dbfile = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
try
{
using (var database = new LiteDatabase(dbfile))
{
var acol = database.GetCollection<A>();
const string id1 = "a";
const string id2 = "b";
acol.Upsert(new A()
{
Id = "1",
ListB =
{
new B() { Key = "x", Values = { id1 } },
}
});
acol.Upsert(new A()
{
Id = "2",
ListB =
{
new B() { Key = "x", Values = { id2 } },
}
});
List<A> alist;
// Wrong results
alist = acol.Query().Where(n => n.ListB.Where(t => t.Key == "x" && t.Values[0] == id1).Any()).ToList();
Console.WriteLine(alist[0].Id); // Should output 1 => OK
alist = acol.Query().Where(n => n.ListB.Where(t => t.Key == "x" && t.Values[0] == id2).Any()).ToList();
Console.WriteLine(alist[0].Id); // Should output 2 but outputs 1 => WRONG
// If we swap id1 and id2, we will get 2 in both outputs, which is also wrong
// Correct results if we load all objects to memory and then run query
alist = acol.Query().ToList().Where(n => n.ListB.Where(t => t.Key == "x" && t.Values[0] == id1).Any()).ToList();
Console.WriteLine(alist[0].Id); // Should output 1 => OK
alist = acol.Query().ToList().Where(n => n.ListB.Where(t => t.Key == "x" && t.Values[0] == id2).Any()).ToList();
Console.WriteLine(alist[0].Id); // Should output 2 => OK
Console.ReadKey();
}
}
finally
{
File.Delete(dbfile);
}
public class A
{
public string Id { get; set; }
public List<B> ListB { get; set; } = new();
}
public class B
{
public string Key { get; set; }
public List<string> Values { get; set; } = new();
}
Expected behavior
Query should return correct result.
Additional context
Apparently the inner function is using the parameters passed in the previous call due to the cache in BsonExpression. If we bypass the cache in BsonExpression.Compile() then the query returns the correct results.
The text was updated successfully, but these errors were encountered:
Version
v5.0.15
Describe the bug
Query returns wrong results.
Code to Reproduce
Expected behavior
Query should return correct result.
Additional context
Apparently the inner function is using the parameters passed in the previous call due to the cache in
BsonExpression
. If we bypass the cache inBsonExpression.Compile()
then the query returns the correct results.The text was updated successfully, but these errors were encountered: