public static SqlProc ProcNamed(object namedParam, Context db = null) { var properties = new NameProperties(namedParam); if (properties.List.Count == 0) { return(null); } string cmdText = properties.GetValue(namedParam, properties.FirstName()) as string; Ai.Guard.Check(cmdText.Length > 4); var proc = SqlProcExt.CmdText(cmdText); var listParam = new List <SqlParameter>(); foreach (string itemName in properties.Names(1)) { var val = Ai.Reflection.Utils.GetPropertyValue(namedParam, itemName); if (val != null) { listParam.Add(SqlProc.AddWithValue("@" + itemName, val)); } } proc.Param = listParam; proc.Context = db; return(proc); }
public static SqlProc WithParam(this SqlProc proc, string name, object value) { if (proc.Param == null) { proc.Param = new List <SqlParameter>() { SqlProc.AddWithValue(name, value) } } ; else { proc.Param.Add(SqlProc.AddWithValue(name, value)); } return(proc); }
public bool ExecNamed(DbContext context, object paramNamed, int iFrom = 0, int iTake = 0) { var prop = new NameProperties(paramNamed); string execName = prop.GetValue(paramNamed, prop.FirstName()) as string; var proc = SqlProcExt.CmdText(execName, context); var paramList = new List <SqlParameter>(); foreach (string item in prop.Names(1)) { paramList.Add(SqlProc.AddWithValue("@" + item, prop.GetValue(paramNamed, item))); } if (paramList.Count > 0) { proc.Param = paramList; } return(ExecProc(proc, iFrom, iTake)); }
public static List <SqlParameter> Parse(object namedParam, int skipFrom = 0) { var properties = new NameProperties(namedParam); if (properties.List.Count == 0) { return(null); } var listParam = new List <SqlParameter>(); foreach (string itemName in properties.Names(skipFrom)) { var val = Utils.GetPropertyValue(namedParam, itemName); if (val != null) { listParam.Add(SqlProc.AddWithValue("@" + itemName, val)); } } return(listParam); }