Ejemplo n.º 1
0
 public static Func <SqlDataReader> LazyReader(ISqlProc proc
                                               , Action <SqlDataReader> readerGet
                                               , Action <SqlCommand> setupCmd = null
                                               , Action <Exception> onError   = null)
 {
     return(SqlMultiDyn.LazyReader(proc, readerGet, setupCmd, onError));
 }
Ejemplo n.º 2
0
        public static IEnumerable <T> MultiExec <T>(this SqlProc proc,
                                                    Action <SqlDataReader, SqlField[]> onReadFields = null,
                                                    Action <Exception> onError = null)
            where T : class
        {
            var cmd    = proc.CreateCommand();
            var mapper = new DbObject();

            SqlDataReader reader = SqlMultiDyn.ExecMultiReader(proc, onError: onError);

            if (reader == null)
            {
                yield break;
            }

            IEnumerable <object[]> worker = ExecMulti(proc, reader, mapper, onReadFields, progress: null);
            var numerator = worker.GetEnumerator();

            Guard.Check(numerator.Current == null);
            while (numerator.MoveNext())
            {
                object[] record = numerator.Current;
                T        obj    = (T)Activator.CreateInstance <T>();

                yield return(obj);
            }
        }
Ejemplo n.º 3
0
        public static ResultDyn ExecProcResultDyn(this ISqlProc proc
                                                  , Action <SqlCommand> setupCmd = null
                                                  , Action <Exception> onError   = null)
        {
            SqlDataReader reader = null;

            return(DbEnumeratorData.GetResultDyn(SqlMultiDyn.LazyReader(proc, (r) => reader = r, setupCmd, onError)));
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public MultiResult <T> Prepare(SqlProc proc
                                       , Action <SqlCommand> setup        = null
                                       , Action <SqlField[]> onReadFields = null
                                       , bool noMoveFirst = false
                                       )
        {
            this.proc = proc;
            var mapper = new DbObject();

            numerator = DbEnumeratorData.GetEnumerator(() =>
            {
                this.reader = SqlMultiDyn.ExecMultiReader(proc, setup, progress: null);
                return(reader);
            });

            if (numerator == null)
            {
                return(null);
            }
            if (reader.IsClosed || reader.Depth != 0)
            {
                return(null);
            }

            if (noMoveFirst)
            {
                return(this);
            }

            numerator.MoveNext();
            var rec = numerator.Current as object[]; // DbDataRecord;

            mapHelper = mapper.GetProperties(reader);

            Fields      = reader.GetFields(); // SqlFieldArray
            FirstRecord = rec;
            // mapHelper.SetValues(mapHelper.DbRecordArray());
            return(this);
        }