Exemplo n.º 1
0
        private static DbParameter[] CreateParametersForEntity(ref string sql, object entity, string suffix = null)
        {
            if (suffix == null)
            {
                suffix = string.Empty;
            }
            var sqlVariables = ParseSqlVariable(sql);

            if (sqlVariables.Count <= 0)
            {
                return(null);
            }

            var paramList = new List <DbParameter>(sqlVariables.Count);

            sqlVariables.Sort((a, b) => a.Length - b.Length);

            foreach (string sqlVar in sqlVariables)
            {
                var value     = GetObjectValue(entity, sqlVar.Substring(1));
                var newSqlVar = sqlVar + suffix;
                sql = SQLAnalyser.ReplaceParam(sql, sqlVar, newSqlVar);
                paramList.Add(CreateParameter(newSqlVar, value));
            }
            return(paramList.ToArray());
        }
Exemplo n.º 2
0
 private static List <string> ParseSqlVariable(string sql)
 {
     if (string.IsNullOrWhiteSpace(sql))
     {
         return(null);
     }
     return(SQLAnalyser.GetInputParamList(sql));
 }