public TOut ExecuteAndLoad <TIn, TOut>(String source, String command, TIn element) where TIn : class where TOut : class
        {
            TOut outValue = null;

            using (var p = _profiler.Start(command))
            {
                using (var cnn = GetConnection(source))
                {
                    using (var cmd = cnn.CreateCommandSP(command))
                    {
                        var retParam = SetParametersFrom(cmd, element);
                        using (var rdr = cmd.ExecuteReader())
                        {
                            var helper = new LoadHelper <TOut>();
                            helper.ProcessRecord(rdr);
                            if (rdr.Read())
                            {
                                outValue = helper.ProcessFields(rdr);
                            }
                        }
                        SetReturnParamResult(retParam, element);
                    }
                }
            }
            return(outValue);
        }
Exemple #2
0
        public T Load <T>(String source, String command, System.Object prms = null) where T : class
        {
            using var token = _profiler.Start(command);
            using var cnn   = GetConnection(source);
            using var cmd   = cnn.CreateCommandSP(command, CommandTimeout);

            var helper = new LoadHelper <T>();

            SqlExtensions.SetFromDynamic(cmd.Parameters, prms);

            using var rdr = cmd.ExecuteReader();
            helper.ProcessRecord(rdr);
            if (rdr.Read())
            {
                T result = helper.ProcessFields(rdr);
                return(result);
            }
            return(null);
        }
Exemple #3
0
        public async Task <TOut> ExecuteAndLoadAsync <TIn, TOut>(String source, String command, TIn element) where TIn : class where TOut : class
        {
            TOut outValue = null;

            using var token = _profiler.Start(command);
            using var cnn   = await GetConnectionAsync(source);

            using var cmd = cnn.CreateCommandSP(command, CommandTimeout);

            var retParam = SetParametersFrom(cmd, element);

            using (var rdr = await cmd.ExecuteReaderAsync())
            {
                var helper = new LoadHelper <TOut>();
                helper.ProcessRecord(rdr);
                if (await rdr.ReadAsync())
                {
                    outValue = helper.ProcessFields(rdr);
                }
            }
            SetReturnParamResult(retParam, element);
            return(outValue);
        }
 public async Task <T> LoadAsync <T>(String source, String command, System.Object prms = null) where T : class
 {
     using (var p = _profiler.Start(command))
     {
         var helper = new LoadHelper <T>();
         using (var cnn = await GetConnectionAsync(source))
         {
             using (var cmd = cnn.CreateCommandSP(command))
             {
                 SqlExtensions.SetFromDynamic(cmd.Parameters, prms);
                 using (var rdr = await cmd.ExecuteReaderAsync())
                 {
                     helper.ProcessRecord(rdr);
                     if (await rdr.ReadAsync())
                     {
                         T result = helper.ProcessFields(rdr);
                         return(result);
                     }
                 }
             }
         }
     }
     return(null);
 }