示例#1
0
        public PagingQueryDecorator(SelectQuery innerQuery, int skip, int take)
        {
            if (string.IsNullOrEmpty(innerQuery.OrderBy.ToString()))
            {
                throw new DataMappingException("A paged query must specify an order by clause.");
            }

            _innerQuery = innerQuery;
            _firstRow = skip + 1;
            _lastRow = skip + take;
        }
示例#2
0
        public void SqlServerSelectQuery_MethodExpression_BinaryExpression()
        {
            // Arrange
            var command = new System.Data.SqlClient.SqlCommand();
            ColumnMapCollection columns = MapRepository.Instance.GetColumns(typeof(Person));
            MappingHelper mappingHelper = new MappingHelper(command);

            Person person = new Person();
            person.ID = 1;
            person.Name = "Jordan";
            person.Age = 33;
            person.IsHappy = true;
            person.BirthDate = new DateTime(1977, 1, 22);

            List<Person> list = new List<Person>();

            var where = new WhereBuilder<Person>(command, p => p.Name.Contains("John") && p.Age > 5, false);
            IQuery query = new SelectQuery(columns, "dbo.People", where.ToString(), "", false);

            // Act
            string queryText = query.Generate();

            // Assert
            Assert.IsNotNull(queryText);
            Assert.AreEqual(command.Parameters["@P0"].Value, "John");
            Assert.AreEqual(command.Parameters["@P1"].Value, 5);
            Assert.IsTrue(queryText.Contains("[Name] LIKE '%' + @P0 + '%'"));
            Assert.IsTrue(queryText.Contains("[Age] > @P1"));            
        }
 public RowCountQueryDecorator(SelectQuery innerQuery)
 {
     _innerQuery = innerQuery;
 }
示例#4
0
        public void SqlServerSelectQuery_MethodExpression_BinaryExpression()
        {
            // Arrange
            var command = new System.Data.SqlClient.SqlCommand();
            var db = MockRepository.GenerateStub<IDataMapper>();
            db.Expect(d => d.Command).Return(command);
            ColumnMapCollection columns = MapRepository.Instance.GetColumns(typeof(Person));
            MappingHelper mappingHelper = new MappingHelper(db);
            var orderBy = MockRepository.GenerateStub<ISortQueryBuilder>();
            orderBy.Expect(o => o.BuildQuery()).Return("");

            Person person = new Person();
            person.ID = 1;
            person.Name = "Jordan";
            person.Age = 33;
            person.IsHappy = true;
            person.BirthDate = new DateTime(1977, 1, 22);

            List<Person> list = new List<Person>();

            TableCollection tables = new TableCollection { new Table(typeof(Person)) };
            Expression<Func<Person, bool>> filter = p => p.Name.Contains("John") && p.Age > 5;
            var where = new WhereBuilder<Person>(command, new SqlServerDialect(), filter, tables, false, true);
            IQuery query = new SelectQuery(new SqlServerDialect(), tables, where.ToString(), orderBy, false);

            // Act
            string queryText = query.Generate();

            // Assert
            Assert.IsNotNull(queryText);
            Assert.AreEqual(command.Parameters["@P0"].Value, "John");
            Assert.AreEqual(command.Parameters["@P1"].Value, 5);
            Assert.IsTrue(queryText.Contains("[Name] LIKE '%' + @P0 + '%'"));
            Assert.IsTrue(queryText.Contains("[Age] > @P1"));
        }
示例#5
0
 public SqliteRowCountQueryDecorator(SelectQuery innerQuery)
 {
     _innerQuery = innerQuery;
 }