Exemplo n.º 1
0
        ExecFirst <T>(this Context db, object sqlProcNamed,
                      Action <Exception> onError = null
                      ) where T : class
        {
            var proc = SqlProcExt.ProcNamed(sqlProcNamed);

            proc.Context = db;
            SqlDataReader reader    = null;
            var           numerator = ContextMulti.MultiExec <T>(proc,
                                                                 onReadFields: (r, fields) =>
            {
                reader = r;
            }, onError: onError);

            if (reader == null)
            {
                var num = numerator.GetEnumerator();
                num.MoveNext();
            }

            if (numerator == null)
            {
                numerator = Enumerable.Empty <T>();
            }

            return(new KeyValuePair <SqlDataReader, IEnumerable <T> >(reader, numerator));
        }
Exemplo n.º 2
0
        public static MultiResult <T> MultiExec <T>(this Context db, object sqlProcNamed) where T : class
        {
            var proc = SqlProcExt.ProcNamed(sqlProcNamed);

            proc.Context = db;
            return(MultiExec <T>(proc));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public static MultiResult <XElement> MultiXElem(this Context db, object sqlProcNamed)
        {
            var proc = SqlProcExt.ProcNamed(sqlProcNamed);

            proc.Context = db;
            return(MultiXElem(proc));
        }
Exemplo n.º 5
0
        public bool Exec(Context context, string[] param, int iFrom = 0, int iTake = 0)
        {
            string execName = param[0];

            var proc = SqlProcExt.CmdText(execName, context);

            return(ExecProc(proc, iFrom, iTake));
        }
Exemplo n.º 6
0
        public bool ExecNamed(Context context, object namedParam)
        {
            // NameProperties prop = new NameProperties(namedParam);
            var proc = SqlProcExt.ProcNamed(namedParam);

            proc.Context = context;

            return(ExecProc(proc));
        }
Exemplo n.º 7
0
        public static ResultDyn ExecNamedResultDyn(this Context db, object named
                                                   , Action <SqlCommand> setupCmd = null
                                                   , Action <Exception> onError   = null)
        {
            var           proc   = SqlProcExt.ProcNamed(named, db);
            SqlDataReader reader = null;

            return(DbEnumeratorData.GetResultDyn(LazyReader(proc, (r) => reader = r, setupCmd, onError)));
        }
Exemplo n.º 8
0
        public static KeyValuePair <ResultDyn, IEnumerable <T> > ResultObj <T>(this Context db, object named
                                                                               , Action <SqlCommand> setupCmd = null
                                                                               , Action <Exception> onError   = null)
        {
            var           proc   = SqlProcExt.ProcNamed(named);
            SqlDataReader reader = null;
            ResultDyn     dyn    = DbEnumeratorData.GetResultDyn(LazyReader(proc, (r) => reader = r, setupCmd, onError));

            return(CastResult <T>(dyn, onError));
        }
Exemplo n.º 9
0
        public bool ExecNamed(Context context, object paramNamed, int iFrom = 0, int iTake = 0)
        {
            NameProperties prop     = new NameProperties(paramNamed);
            string         execName = prop.GetValue(paramNamed, prop.FirstName()) as string;
            var            proc     = SqlProcExt.CmdText(execName, context);

            if (prop.List.Count > 1)
            {
                proc.Param = NameProperties.Parse(paramNamed, 1);
            }

            return(ExecProc(proc, iFrom, iTake));
        }
Exemplo n.º 10
0
        ExecDyn(this Context db, object namedParam
                , Action <SqlCommand> setupCmd = null)
        {
            var proc = SqlProcExt.ProcNamed(namedParam);

            proc.Context = db;

            SqlDataReader readerGet = null;
            var           numerator
                = SqlMultiDyn.ResultDyn(proc, (reader) => readerGet = reader, setupCmd);

            if (numerator.Current == null || readerGet == null)
            {
                numerator.MoveNext();
            }

            return(new KeyValuePair <SqlDataReader, DbEnumeratorData <ExpandoObject> >(readerGet, numerator));
        }
Exemplo n.º 11
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));
        }