public NisreDbException(NpgsqlException exception, PgParam parameters)
        {
            if (exception.Data.Count <= 0)
            {
                return;
            }
            var code    = exception.Data["Code"].ToString();
            var message = exception.Data["MessageText"].ToString();

            var where = exception.Data["Where"].ToString();
            var hint = exception.Data["Hint"].ToString();

            ExceptionData.Add("code", code);
            ExceptionData.Add("messageText", message);
            ExceptionData.Add("where", where);
            ExceptionData.Add("hint", hint);
            ExceptionData.Add("parameters", parameters.GetParamatersInfo().ToJson());
            if (code == "P0001")
            {
                this.CustomException = true;
                this.Message         = message;
            }
            else
            {
                CustomException = false;
                Message         = "System Error";
            }
        }
示例#2
0
        public async Task <IEnumerable <T> > Query <T>(string procedure, PgParam parameter)
        {
            try
            {
                using var db = new NpgsqlConnection(_dbConnectionString);
                await db.OpenAsync();

                return(await db.QueryAsync <T>(procedure, parameter, commandType : CommandType.StoredProcedure));
            }
            catch (NpgsqlException ex)
            {
                var exception = new NisreDbException(ex, parameter);
                throw exception;
            }
            catch (Exception e)
            {
                throw new NisreDbException(e);
            }
        }
示例#3
0
        public async Task Execute(string procedure, PgParam parameter)
        {
            try
            {
                using var db = new NpgsqlConnection(_dbConnectionString);
                await db.OpenAsync();

                await db.ExecuteAsync(procedure, parameter, commandType : CommandType.StoredProcedure);
            }
            catch (NpgsqlException ex)
            {
                var exception = new NisreDbException(ex, parameter);
                throw exception;
            }
            catch (Exception e)
            {
                throw new NisreDbException(e);
            }
        }