dbelmont / ExpressionBuilder

A library that provides a simple way to create lambda expressions to filter lists and database queries.
Apache License 2.0
372 stars 105 forks source link

Error to filter on bool? #44

Open dust63 opened 5 years ago

dust63 commented 5 years ago

I have strange error when I want to filter to a bool?.

See my unit test below to reproduce the bug.

    [TestClass]
    public class ExpressionBuilderTest
    {

        class Person
        {
            public bool? IsValid { get; set; }
        }

        [TestMethod]
        public void TestFilterNullableBool()
        {

            var persons = new List<Person>();
            var person = new Person();
            persons.Add(person);

            var filter = new Filter<Person>();
            filter.By("IsValid", Operation.IsNull);
            Assert.IsTrue(persons.Count(filter) == 1);

            filter = new Filter<Person>();
            filter.By("IsValid", Operation.EqualTo, true);
            Assert.IsTrue(persons.Count(filter) == 0);

            person.IsValid = true;
            Assert.IsTrue(persons.Count(filter) == 1);
        }
    }