Ejemplo n.º 1
0
    /// <summary>
    /// 查询所有数据-包含字段
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="dataSource"></param>
    /// <param name="paramerList"></param>
    /// <param name="top"></param>
    /// <param name="inclusionList"></param>
    /// <returns></returns>
    public StringBuilder GetSelectDictionaryCmdText <T>(IDataSource dataSource, ref List <DbParameter> paramerList, StringBuilder whereStr, StringBuilder orderStr, int?top = null, params string[] inclusionList)
    {
        var cmdText    = new StringBuilder();
        var entityType = typeof(T);

        var tableName = entityType.GetDataTableName();

        tableName = string.Format(dataSource.DbFactory.DbProvider.FieldFormat, tableName);

        var fields = dataSource.CreateAllEntityDicSql <T>(inclusionList);

        if (top != null && top.Value > 0)
        {
            var topparameter = dataSource.DbFactory.DbProvider.ParameterPrefix + "topParameter";
            paramerList.Add(dataSource.CreateParameter(topparameter, top.Value));
            cmdText.AppendFormat("SELECT * FROM (select r.*,rownum rowsn from(SELECT {1} FROM {0} {2} {3})r) where rowsn<={4} ", tableName, fields, whereStr, orderStr, topparameter);
        }
        else
        {
            cmdText.AppendFormat("SELECT {1} FROM {0} {2} {3} ", tableName, fields, whereStr, orderStr);
        }


        return(cmdText);
    }