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] when param in where not constant #1607

Closed
zamis opened this issue Apr 2, 2020 · 1 comment
Closed

[BUG] when param in where not constant #1607

zamis opened this issue Apr 2, 2020 · 1 comment
Labels

Comments

@zamis
Copy link

zamis commented Apr 2, 2020

Version
Which LiteDB version/OS/.NET framework version are you using. (REQUIRED)
5.0.5 on master

Describe the bug
A clear and concise description of what the bug is.

when
db.GetCollection("Person").Find(x => x.Sex == PersonSex.Female);

  • is ok

when
var PersonSexFemale = PersonSex.Female;
var p = db.GetCollection("Person").Find(x => x.Sex == PersonSexFemale);

  • Exception
    [xUnit.net 00:00:44.75] LiteDB.Tests.Database.Enum_Tests.FindFemale [FAIL]
    [xUnit.net 00:00:44.76] System.NullReferenceException : Object reference not set to an instance of an object.
    [xUnit.net 00:00:44.76] Stack Trace:
    [xUnit.net 00:00:44.76] E:\Projects\TeamMe\LiteDB\LiteDB\Client\Mapper\Linq\LinqExpressionVisitor.cs(432,0): at LiteDB.LinqExpressionVisitor.VisitBinary(BinaryExpression node)
    [xUnit.net 00:00:44.76] at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
    [xUnit.net 00:00:44.76] at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
    [xUnit.net 00:00:44.76] at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression1 node) [xUnit.net 00:00:44.76] E:\Projects\TeamMe\LiteDB\LiteDB\Client\Mapper\Linq\LinqExpressionVisitor.cs(95,0): at LiteDB.LinqExpressionVisitor.VisitLambda[T](Expression1 node)
    [xUnit.net 00:00:44.76] at System.Linq.Expressions.Expression1.Accept(ExpressionVisitor visitor) [xUnit.net 00:00:44.76] at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) [xUnit.net 00:00:44.76] E:\Projects\TeamMe\LiteDB\LiteDB\Client\Mapper\Linq\LinqExpressionVisitor.cs(64,0): at LiteDB.LinqExpressionVisitor.Resolve(Boolean predicate) [xUnit.net 00:00:44.76] E:\Projects\TeamMe\LiteDB\LiteDB\Client\Mapper\BsonMapper.cs(175,0): at LiteDB.BsonMapper.GetExpression[T,K](Expression1 predicate)
    [xUnit.net 00:00:44.76] E:\Projects\TeamMe\LiteDB\LiteDB\Client\Database\Collections\Find.cs(54,0): at LiteDB.LiteCollection1.Find(Expression1 predicate, Int32 skip, Int32 limit)
    [xUnit.net 00:00:44.76] e:\Projects\TeamMe\LiteDB\LiteDB.Tests\Database\Enum_Tests.cs(42,0): at LiteDB.Tests.Database.Enum_Tests.FindFemale()

Code to Reproduce
Write a small snippet to isolate your bug and could be possible to our team test. (REQUIRED)

public class Enum_Tests
    {
        public enum PersonSex
        {
            Male,
            Female
        }

        public class Person
        {
            public int Id { get; set; }
            public string Fullname { get; set; }
            public PersonSex Sex { get; set; }
        }


        [Fact]
        public void FindFemale()
        {
            using (var f = new TempFile())
            {
                using (var db = new LiteDatabase(f.Filename))
                {
                    var col = db.GetCollection<Person>("Person");

                    col.Insert(new Person { Fullname = "John", Sex = PersonSex.Male });
                    col.Insert(new Person { Fullname = "Doe", Sex = PersonSex.Male });
                    col.Insert(new Person { Fullname = "Joana", Sex = PersonSex.Female });
                    col.Insert(new Person { Fullname = "Marcus", Sex = PersonSex.Male });
                }
                // close datafile

                using (var db = new LiteDatabase(f.Filename))
                {
                    var PersonSexFemale = PersonSex.Female;
                    var p = db.GetCollection<Person>("Person").Find(x => x.Sex == PersonSexFemale);

                    p.Count().Should().Be(1);
                }
            }
        }
    }

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots/Stacktrace
If applicable, add screenshots/stacktrace

Additional context
Add any other context about the problem here.

@lbnascimento
Copy link
Collaborator

@zamis This issue was fixed in the master and its fix will be present in the next incremental release.

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