Exemple #1
0
        /// <summary>
        /// Insert语句生成
        /// </summary>
        /// <typeparam name="T">Model泛型</typeparam>
        /// <typeparam name="P">sql参数类型,SqlParameter/OracleParameter</typeparam>
        /// <param name="model">实例</param>
        /// <param name="parameterList">参数数组</param>
        /// <returns>Insert语句</returns>
        public string InsertSqlGenerate <T>(T model, ref List <DbParameter> parameterList)
        {
            string cacheSQL = SQLDataCache.GetHashTableData(model, CRUDEnum.INSERT);
            string result   = string.Empty;

            if (!string.IsNullOrEmpty(cacheSQL))
            {
                result = cacheSQL;
            }
            else
            {
                result = "insert into {0}({2}) values({1})";
                result = string.Format(result, TableGenerator.Table <T>(), ParameterGenerator.ParameterString <T>(), TableGenerator.AllColumn <T>());
            }
            List <DbParameter> paramList = SQLDataCache.GetParameterCacheData <DbParameter>(model);;

            if (paramList == null)
            {
                parameterList = ParameterGenerator.ParametersArray <T>(model);
                SQLDataCache.ModelParameterPush <DbParameter>(model, parameterList);
            }
            else
            {
                parameterList.AddRange(paramList.ToArray());
                ParameterGenerator.ModelValueToParamListPush(parameterList, model);
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 生成更新语句
        /// </summary>
        /// <typeparam name="T">泛型T Model</typeparam>
        /// <param name="model">实例</param>
        /// <param name="parameterList">参数数组</param>
        /// <returns></returns>
        /// <remarks>
        /// eg:UPDATE USERS SET NAME = @NAME WHERE ID = @ID
        /// </remarks>
        public string UpdateSqlGenerate <T>(T model, ref List <DbParameter> parameterList)
        {
            string cacheSQL = SQLDataCache.GetHashTableData(model, CRUDEnum.UDPATE);
            string result   = string.Empty;

            if (!string.IsNullOrEmpty(cacheSQL))
            {
                result = cacheSQL;
            }
            else
            {
                result = "update {0} set {1} where {2} = {3}";
                result = string.Format(result, TableGenerator.Table <T>(), ParameterGenerator.ParameterStringWithoutKey <T>(), ParameterGenerator.KeyString <T>(), ParameterGenerator.KeyParameterString <T>());
                SQLDataCache.ModelCURDHandleSQLPush(model, CRUDEnum.UDPATE, result);
            }

            List <DbParameter> paramList = SQLDataCache.GetParameterCacheData <DbParameter>(model);

            if (paramList == null)
            {
                parameterList = ParameterGenerator.ParametersArray <T>(model);
                SQLDataCache.ModelParameterPush <DbParameter>(model, parameterList);
            }
            else
            {
                parameterList.AddRange(paramList.ToArray());
                ParameterGenerator.ModelValueToParamListPush(parameterList, model);
            }
            return(result);
        }