Пример #1
0
        public static Task <IList <T> > ExecAsync <T>(this Context context, SqlProc procedure, IList <T> list,
                                                      TaskScheduler scheduler, Action <double> progress) where T : class
        {
            Func <IList <T> > func = () =>
            {
                var conn = new SqlConnection();
                conn.ConnectionString = context.ConnectionString();
                if (context.OnBeforeOpen != null)
                {
                    context.OnBeforeOpen(context, new SqlConnEventArgs(conn));
                }
                conn.Open();

                var procClone = new SqlProc()
                {
                    CmdText = procedure.CmdText, Connection = conn, Param = procedure.Param
                };

                Trace.WriteLine("SqlProc: " + procClone.CmdText);
                var res = procClone.Exec <T>(list, progress); // .Result;
                return(res);
            };

            var task = Task.Factory.StartNew <IList <T> >(func, CancellationToken.None, TaskCreationOptions.LongRunning, scheduler);

            return(task);
        }
Пример #2
0
        public IList <T> Exec <T>(SqlProc procedure) where T : class
        {
            if (procedure.Connection == null)
            {
                procedure.Connection = SqlConnection;
                if (procedure.Connection == null)
                {
                    throw new ArgumentNullException("procedure.Connection");
                }
            }

            Trace.WriteLine("SqlProc: " + procedure.CmdText);

            var list = new Collection <T>();

            return(procedure.Exec <T>(list, null)); // .Result;
        }