示例#1
0
        public void BuildContainExpression()
        {
            //Arrange
            List <Person> people = FakeData.People();

            Expression <Func <Person, bool> > express = PredicateBuilder.BuildContains <Person>("FirstName", "Du");

            Func <Person, bool> func = express.Compile();

            string format = express.ToString();

            var result = people.Where(func);

            var expectedResult = people.Where(p => p.FirstName.ToLower().Contains("du"));

            Assert.That(result.Count(), Is.EqualTo(expectedResult.Count()));
        }
示例#2
0
        public static IQueryable <T> SearchContain <T>(IQueryable <T> source, string propertyName, string phrase)
        {
            Expression <Func <T, bool> > express = PredicateBuilder.BuildContains <T>(propertyName, phrase);

            return(source.Where(express.Compile()).AsQueryable());
        }