Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Comparison with index not processed correctly #1684

Closed
mikhail-khalizev opened this issue May 13, 2020 · 1 comment
Closed

[BUG] Comparison with index not processed correctly #1684

mikhail-khalizev opened this issue May 13, 2020 · 1 comment
Labels

Comments

@mikhail-khalizev
Copy link

Version
5.0.8

Describe the bug
Hi.

Or I made some stupid mistake in my code and don’t understand it. Or, a comparison condition with an index is not processed correctly.

Take a look at the test below: it adds 10 elements, and then all the elements from the collection are queried in different ways. The first two tests are successful. And the last 2 for some reason fail.

Code to Reproduce

public class StateModel
{
    [BsonId] 
    public int Id { get; set; }
}


[Fact]
public void StateTest()
{
    using (var db = new LiteDatabase(":memory:"))
    {
        var col = db.GetCollection<StateModel>("col");

        var count = 10;
        var firstId = 5;
        var lastId = firstId + count - 1;

        for (var i = firstId; i <= lastId; i++)
        {
            col.Insert(new StateModel
            {
               Id = i
            });
        }

        var list = col.Query().ToList();
        list.Should().HaveCount(count);

        list = col.Query()
            .Where(x => firstId <= x.Id)
            .ToList();
        list.Should().HaveCount(count);

        list = col.Query()
            .Where(x => x.Id <= lastId)
            .ToList();
        list.Should().HaveCount(count);

        list = col.Query()
            .Where(x => firstId <= x.Id && x.Id <= lastId)
            .ToList();
        list.Should().HaveCount(count);
    }
}

Expected behavior
Test passed.

@lbnascimento
Copy link
Collaborator

@mikhail-khalizev This issue has been fixed in master and its fix will be present in the next incremental release.

In the meantime, make sure the indexed field is always on the left part of the expression (e.g.: x.Id >= firstId instead of firstId <= x.Id).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants