コード例 #1
0
        /// <summary>
        /// 构建获取前topNumber记录的SQL
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="topNumber"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        protected string BuildTopSql <T>(int topNumber, string sql)
        {
            PocoData data       = PocoData.ForType(typeof(T), DefaultMapper);
            string   primaryKey = data.TableInfo.TableName + "." + data.TableInfo.PrimaryKey;

            if (this.EnableAutoSelect)
            {
                sql = AutoSelectHelperExt.AddSelectClause <T>(Provider, sql, DefaultMapper, primaryKey);
            }
            return(this.BuildTopSql(topNumber, sql));
        }
コード例 #2
0
        /// <summary>
        /// 创建分页的SQL语句
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="maxRecords"></param>
        /// <param name="skip"></param>
        /// <param name="take"></param>
        /// <param name="sql"></param>
        /// <param name="args"></param>
        /// <param name="sqlCount"></param>
        /// <param name="sqlPage"></param>
        protected void BuildPagingPrimaryKeyQueries <T>(long maxRecords, long skip, long take, string sql, ref object[] args, out string sqlCount, out string sqlPage)
        {
            PocoData data       = PocoData.ForType(typeof(T), DefaultMapper);
            string   primaryKey = string.Empty;

            if (sql.Contains(data.TableInfo.TableName))
            {
                primaryKey = data.TableInfo.TableName + "." + data.TableInfo.PrimaryKey;
            }
            else
            {
                primaryKey = data.TableInfo.PrimaryKey;
            }
            if (this.EnableAutoSelect)
            {
                sql = AutoSelectHelperExt.AddSelectClause <T>(Provider, sql, DefaultMapper, primaryKey);
            }
            this.BuildPagingPrimaryKeyQueries(maxRecords, skip, take, primaryKey, sql, ref args, out sqlCount, out sqlPage);
        }