示例#1
0
        private void Parameter(string name)
        {
            var where = LamdaQueryParser.Where <User>(u => u.Name == name) as SingleQueryFilter;
            var filter = new SingleQueryFilter();

            filter.AddEqual(nameof(User.Name), name);
            Compare(where, filter);
        }
示例#2
0
        public void TestParse()
        {
            Expression <Func <User, bool> > lamda1 = u => u.Id == 1;
            Expression <Func <User, bool> > lamda2 = u => u.Id == 3 || u.Name == "3";
            Expression <Func <User, bool> > lamda3 = u => u.Id == 3 && u.Name == "3" && u.Id == 0;
            Expression <Func <User, bool> > lamda4 = u => (u.Id == 3 && u.Name == "3") || u.Id == 0;
            Expression <Func <User, bool> > lamda5 = u => (u.Id == 3 && u.Name == "3") || (u.Id == 0 && u.Name == "4");

            #region lamda1
            var query1           = LamdaQueryParser.Where <User>(lamda1) as SingleQueryFilter;
            SingleQueryFilter qf = new SingleQueryFilter();
            qf.AddEqual(nameof(User.Id), 1);
            Compare(query1, qf);
            #endregion

            #region lamda2
            var query2 = LamdaQueryParser.Where <User>(lamda2) as CombinedQueryFilter;

            SingleQueryFilter qf1 = new SingleQueryFilter();
            qf1.AddEqual(nameof(User.Id), 3);
            SingleQueryFilter qf2 = new SingleQueryFilter();
            qf2.AddEqual(nameof(User.Name), "3");


            CombinedQueryFilter cf1 = new CombinedQueryFilter(qf1, qf2, BooleanClause.Or);

            Compare(query2, cf1);
            #endregion

            #region lamda3
            var query3 = LamdaQueryParser.Where <User>(lamda3) as CombinedQueryFilter;

            SingleQueryFilter qf3 = new SingleQueryFilter();
            qf3.AddEqual(nameof(User.Id), 3);
            SingleQueryFilter qf4 = new SingleQueryFilter();
            qf4.AddEqual(nameof(User.Name), "3");

            CombinedQueryFilter cf2 = new CombinedQueryFilter(qf3, qf4, BooleanClause.And);

            SingleQueryFilter qf5 = new SingleQueryFilter();
            qf5.AddEqual(nameof(User.Id), 0);

            CombinedQueryFilter cf3 = new CombinedQueryFilter(cf2, qf5, BooleanClause.And);

            Compare(query3, cf3);

            #endregion

            #region lamda4
            var query4 = LamdaQueryParser.Where <User>(lamda4) as CombinedQueryFilter;

            SingleQueryFilter qf6 = new SingleQueryFilter();
            qf6.AddEqual(nameof(User.Id), 3);
            SingleQueryFilter qf7 = new SingleQueryFilter();
            qf7.AddEqual(nameof(User.Name), "3");

            CombinedQueryFilter cf4 = new CombinedQueryFilter(qf6, qf7, BooleanClause.And);

            SingleQueryFilter qf8 = new SingleQueryFilter();
            qf8.AddEqual(nameof(User.Id), 0);
            CombinedQueryFilter cf5 = new CombinedQueryFilter(cf2, qf5, BooleanClause.Or);
            Compare(query4, cf5);

            #endregion

            #region lamba5
            var query5 = LamdaQueryParser.Where <User>(lamda5) as CombinedQueryFilter;

            SingleQueryFilter sf1 = new SingleQueryFilter();
            sf1.AddEqual(nameof(User.Id), 3);
            SingleQueryFilter sf2 = new SingleQueryFilter();
            sf2.AddEqual(nameof(User.Name), "3");

            CombinedQueryFilter c1 = new CombinedQueryFilter(sf1, sf2, BooleanClause.And);

            SingleQueryFilter sf3 = new SingleQueryFilter();
            sf3.AddEqual(nameof(User.Id), 0);
            SingleQueryFilter sf4 = new SingleQueryFilter();
            sf4.AddEqual(nameof(User.Name), "4");

            CombinedQueryFilter c2 = new CombinedQueryFilter(sf3, sf4, BooleanClause.And);

            CombinedQueryFilter c3 = new CombinedQueryFilter(c1, c2, BooleanClause.Or);

            Compare(query5, c3);
            #endregion
        }