예제 #1
0
파일: SqlProc.cs 프로젝트: akrisiun/AiLib
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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));
        }
예제 #4
0
        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);
        }