• 大小: 18KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: 数据库
  • 标签: DbHelper  

资源简介

数据库帮助类,支持 oracle sqlserver mysql

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace HY.DataAccess
{
    /// 
    /// 数据库连接事务的Session对象
    /// 

    public class DBSessionbase : IDBSession 
    {
        private IDbConnection _connection;
        private IDbTransaction _transaction;
        private readonly DatabaseType _databaseType;
        private readonly string _connKey;
        
        public DatabaseType DatabaseType
        {
            get { return _databaseType; }
        }

        public string ConnKey
        {
            get { return _connKey; }
        }

        /// 
        /// 数据库连接对象
        /// 

        public IDbConnection Connection
        {
            get { return _connection; }
        }

        /// 
        /// 数据库事务对象
        /// 

        public IDbTransaction Transaction
        {
            get { return _transaction; }
        }

        public DBSessionbase(IDatabase Database)
        {
            _connection = Database.Connection;
            _databaseType = Database.DatabaseType;
            _connKey = Database.ConnKey;
        }

        /// 
        /// 开启会话
        /// 

        /// 
        /// 
        public IDbTransaction Begin(IsolationLevel isolation = IsolationLevel.ReadCommitted)
        {
            _connection.Open();
            _transaction = _connection.BeginTransaction(isolation);
            return _transaction;
        }

        /// 
        /// 事务提交
        /// 

        public void Commit()
        {
            _transaction.Commit();
            _transaction = null;
        }

        /// 
        /// 事务回滚
        /// 

        public void Rollback()
        {
            _transaction.Rollback();
            _transaction = null;
        }

        /// 
        /// 资源释放
        /// 

        public void Dispose()
        {
            if (_connection.State != ConnectionState.Closed)
            {
                if (_transaction != null)
                {
                    _transaction.Rollback();
                    _transaction = null;
                }
                _connection.Close();
                _connection = null;
            }
            GC.SuppressFinalize(this);
        }


    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    I.A....       477  2015-03-03 09:19  HY.DataAccess\app.config

    I.A....      2596  2015-06-09 09:16  HY.DataAccess\DBSession.cs

    I.A....      3163  2015-08-05 17:56  HY.DataAccess\HY.DataAccess.csproj

    I.A....      9564  2015-06-09 09:16  HY.DataAccess\IDBHelper.cs

    I.A....      1412  2015-06-09 09:16  HY.DataAccess\IDbSession.cs

    I.A....     14684  2015-03-03 09:19  HY.DataAccess\MySqlDBHelper\MySqlAdaptor.cs

    I.A....     20991  2015-03-03 09:19  HY.DataAccess\MySqlDBHelper\MySqlHelper.cs

    I.A....     14159  2015-06-09 09:16  HY.DataAccess\OracleDBHelper\OracleAdaptor.cs

    I.A....     18461  2015-06-09 09:16  HY.DataAccess\OracleDBHelper\OracleHelper.cs

    I.A....       316  2015-03-03 09:19  HY.DataAccess\packages.config

    I.A....      3344  2015-03-03 09:19  HY.DataAccess\PageHelper\PageHelper.cs

    I.A....      1350  2015-03-03 09:19  HY.DataAccess\Properties\AssemblyInfo.cs

    I.A....      1377  2015-06-09 09:16  HY.DataAccess\SqlConnectionFactory.cs

    I.A....     13982  2015-06-09 09:16  HY.DataAccess\SqlDBHelper\DBAdaptor.cs

    I.A....     20068  2015-03-03 09:19  HY.DataAccess\SqlDBHelper\SQLHelper.cs

     目录          0  2015-03-03 09:19  HY.DataAccess\MySqlDBHelper

     目录          0  2015-06-09 09:16  HY.DataAccess\OracleDBHelper

     目录          0  2015-03-03 09:19  HY.DataAccess\PageHelper

     目录          0  2015-03-03 09:19  HY.DataAccess\Properties

     目录          0  2015-06-09 09:16  HY.DataAccess\SqlDBHelper

     目录          0  2015-08-26 13:05  HY.DataAccess

----------- ---------  ---------- -----  ----

               125944                    21


评论

共有 条评论

相关资源