Пример #1
0
        /// <summary>
        /// 分页查询年龄大于某个值的学生信息
        /// 支持参数化查询
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagedSqlDataResult <StudentDto> GetStudentssByPagerAndCondition(string name, int pageIndex, int pageSize)
        {
            //防止sql 注入
            //condition.CompanyCode = condition.CompanyCode.ToSafeSqlString();
            //condition.ShopCode = condition.ShopCode.ToSafeSqlString();


            string sqlDataSet = $@"SELECT a.id,a.Name,a.age,b.class_name as ClassName 
from user_students a 
inner join school_class b on a.age=b.age where a.Name like @Name and sex=@Sex";

            try
            {
                var pagerCond = new PagedSqlCondition
                {
                    PageNumber        = pageIndex,
                    PageSize          = pageSize,
                    TableNameOrSqlCmd = sqlDataSet,
                    SqlParameters     = new { Name = name, Sex = 0 },//参数化查询参数设置
                    TableOptions      = PageTableOptions.SqlScripts,
                    SortField         = "id",
                    IsDesc            = false
                };

                var data = this.PageQuery <StudentDto>(pagerCond);

                return(data);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        /// <summary>
        /// 基于分页查询:支持单表和多表的联接查询分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="condition"></param>
        /// <returns></returns>
        public PagedSqlDataResult <T> PageQuery <T>(PagedSqlCondition condition) where T : class
        {
            var pageData = this.dbContext.PageQuery <T>(condition);

            return(pageData);
        }