• 00
  • :
  • 00
  • :
  • 00

GZFramework.DB.Core初始化

单数据库初始化,以MSSQL为例

 

public class DBConfig : IDBConfig
    {
        public static void InitDB()
        {
            GZFramework.DB.Core.Config.DBConfig = new DBConfig();
        }

        IDatabase db;
        public DBConfig()
        {
            string connectionstr = "Data Source=local;Initial Catalog=gzframework;User ID=sa;Password=xxxx";

            const string ProviderName = "System.Data.SqlClient";
            bool b = DatabaseFactory.Validate(connectionstr, ProviderName);

            db = DatabaseFactory.CreateDatabase(connectionstr, ProviderName);
        }


        public IDatabase GetDBConnectionInfo(string DBCode)
        {
            return db;
        }

        public void RefreshDBList()
        {
            
        }

        
    }

 

MSSQL参数集合

public class SqlParameterProvider : DbParameterBase
    {

        //DbParameter GenerateParmeter(string parameterName, object value);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size, string sourceColumn);
        //protected abstract DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size, string sourceColumn, ParameterDirection direction);

        //DbParameter GenerateParmeter(string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, object value);

        //DbParameter SqlParameter(string parameterName, SqlDbType dbType, int size, ParameterDirection direction, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, bool sourceColumnNullMapping, object value, string xmlSchemaCollectionDatabase, string xmlSchemaCollectionOwningSchema, string xmlSchemaCollectionName);
        public void AddParameter(string parameterName, object value)
        {
            SqlParameter parm = new SqlParameter(parameterName, value);
            AddParameter(parm);
        }
        public void AddParameter(string parameterName, SqlDbType dbType, object value)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType);
            parm.Value = value;
            AddParameter(parm);
        }

        public void AddParameter(string parameterName, SqlDbType dbType, int size, object value)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType, size);
            parm.Value = value;
            AddParameter(parm);
        }
        public void AddParameter(string parameterName, SqlDbType dbType, int size, object value, ParameterDirection direction)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType, size);
            parm.Value = value;
            parm.Direction = direction;
            AddParameter(parm);
        }
        public void AddParameter(string parameterName, SqlDbType dbType, int size, object value, string sourceColumn)
        {
            SqlParameter parm = new SqlParameter(parameterName, dbType, size, sourceColumn);
            parm.Value = value;
            AddParameter(parm);
        }
    }
posted @ 2016-04-20 14:38  Garson_Zhang  阅读(637)  评论(0编辑  收藏  举报