Exemple #1
0
 public bool Insert(T t)
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         return(conn.Insert <T>(t));
     }
 }
Exemple #2
0
 public IList <T> GetList()
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         return(conn.GetList <T>().ToList());
     }
 }
Exemple #3
0
 public IList <T> GetList(PredicateGroup group)
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         return(conn.GetList <T>(group).ToList());
     }
 }
Exemple #4
0
 public bool Delete(T t)
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         return(conn.Delete <T>(t));
     }
 }
Exemple #5
0
 public bool Delete(PredicateGroup group)
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         return(conn.Delete <T>(group));
     }
 }
Exemple #6
0
 public T Get(Guid id)
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         return(conn.Get <T>(id));
     }
 }
Exemple #7
0
 public IList <T> GetPager(PredicateGroup group, PageQuery query)
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         return(conn.GetPage <T>(group, query.OrderType.ConvertToSort <T>(), query.PageIndex - 1, query.PageCount).ToList());
     }
 }
Exemple #8
0
 public TResult Get <TResult>(string sql) where TResult : new()
 {
     using (IDbConnection conn = DbConnectFactory.GetPostgresqlConnection())
     {
         conn.Open();
         conn.BeginTransaction();
         IDataReader reader = conn.ExecuteReader(sql);
         DataTable   table  = reader.GetSchemaTable();
         return(DataConvertExtension <TResult> .Get(table));
     }
 }
Exemple #9
0
 public void Transaction(Predicate <IDbConnection> action)
 {
     using (var conn = DbConnectFactory.GetPostgresqlConnection())
     {
         var transaction = conn.BeginTransaction();
         try
         {
             action(conn);
             transaction.Commit();
         }
         catch
         {
             transaction.Rollback();
         }
     }
 }
Exemple #10
0
 public TResult TransactionResult <TResult>(Func <IDbConnection, TResult> funData)
 {
     using (var conn = DbConnectFactory.GetPostgresqlConnection())
     {
         conn.Open();
         var transaction = conn.BeginTransaction();
         try
         {
             var result = funData(conn);
             transaction.Commit();
             return(result);
         }
         catch
         {
             transaction.Rollback();
             throw;
         }
         finally
         {
             conn.Close();
         }
     }
 }
Exemple #11
0
 public bool ExcuteSqlWithTransaction(string sql)
 {
     using (var conn = DbConnectFactory.GetPostgresqlConnection())
     {
         conn.Open();
         var transaction = conn.BeginTransaction();
         try
         {
             int result = conn.Execute(sql);
             transaction.Commit();
             return(result > 0);
         }
         catch
         {
             transaction.Rollback();
             return(false);
         }
         finally
         {
             conn.Close();
         }
     }
 }
Exemple #12
0
 public List <TResult> TransactionResult <TResult>(string sql) where TResult : new()
 {
     using (var conn = DbConnectFactory.GetPostgresqlConnection())
     {
         conn.Open();
         var transaction = conn.BeginTransaction();
         try
         {
             IDataReader reader = conn.ExecuteReader(sql);
             transaction.Commit();
             return(new List <TResult>());
         }
         catch
         {
             transaction.Rollback();
             return(new List <TResult>());
         }
         finally
         {
             conn.Close();
         }
     }
 }