Пример #1
0
 public static DBAccessor Instance()
 {
     if (_instance == null)
     {
         _instance = new DBAccessor();
     }
     _instance.ConnectionDatabase();
     return(_instance);
 }
Пример #2
0
        /// <summary>
        /// 取得一个数据库访问器实例
        /// </summary>
        public static DBAccessor Instance(DBConnection dbc)
        {
            DBAccessor dba = new DBAccessor(dbc)
            {
                AccessorKey = string.Format("{0}_{1}", dbc.ConnName, Guid.NewGuid().ToString())
            };

            _cachedAccessor[dba.AccessorKey] = dba;
            dba.ConnectionDatabase();
            return(dba);
        }
Пример #3
0
        static Dbs()
        {
            DBAccessor.Load(Runtime.ConfigFilePath);
            string path = Runtime.DbsFilePath;

            if (Runtime.DbsFilePath != null && File.Exists(Runtime.DbsFilePath))
            {
                DbsManager dbsManager = null;
                if (dbsManager == null)
                {
                    dbsManager = DbsManager.Instance;
                }
                _dbsList.Clear();
                DBAccessor.ClearCache();
                if (dbsManager.DbsList != null)
                {
                    foreach (var d in dbsManager.DbsList)
                    {
                        if (d.Value.CurrentConnectionString.IsNullOrWhiteSpace())
                        {
                            continue;
                        }
                        DBConnection dbc = new DBConnection()
                        {
                            ConnName      = d.Key.QualifiedName,
                            ConnString    = d.Value.CurrentConnectionString,
                            EdmConnString = d.Value.CurrentConnectionString,
                            Type          = GetDbsType(d.Value.Provider.Code)
                        };
                        _dbsList.Add(new KeyValuePair <string, DBConnection>(dbc.ConnName, dbc));
                    }
                }
                Runtime.Dbs       = _dbsList;
                Dbs.DBConnections = _dbsList;
            }
        }
Пример #4
0
 /// <summary>
 /// 生产对应数据库类型的参数数组
 /// </summary>
 /// <param name="dbc"></param>
 /// <returns></returns>
 public static DbParameter CreateDbParameter(this DBAccessor dba, string paraName = "", object value = null)
 {
     return(dba.CurrentDBConnection.CreateDbParameter(ParameterDirection.Input, paraName, value));
 }