Example #1
0
        /// <summary>构造函数</summary>
        /// <param name="connName">配置名</param>
        private DAL(String connName)
        {
            _ConnName = connName;

            if (!ConnStrs.ContainsKey(connName))
            {
                throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            }

            ConnStr = ConnStrs[connName].ConnectionString;
            if (String.IsNullOrEmpty(ConnStr))
            {
                throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            }

            //// 创建数据库访问对象的时候,就开始检查数据库架构
            //// 尽管这样会占用大量时间,但这种情况往往只存在于安装部署的时候
            //// 要尽可能的减少非安装阶段的时间占用
            //try
            //{
            //    //DatabaseSchema.Check(Db);
            //    SetTables();
            //}
            //catch (Exception ex)
            //{
            //    if (Debug) WriteLog(ex.ToString());
            //}
        }
Example #2
0
        /// <summary>构造函数</summary>
        /// <param name="connName">配置名</param>
        private DAL(String connName)
        {
            _ConnName = connName;

            //if (!ConnStrs.ContainsKey(connName)) throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            if (!ConnStrs.ContainsKey(connName))
            {
                OnResolve?.Invoke(this, new ResolveEventArgs(connName));
            }
            if (!ConnStrs.ContainsKey(connName) && _defs.TryGetValue(connName, out var kv))
            {
                AddConnStr(connName, kv.Item1, null, kv.Item2);
            }
            if (!ConnStrs.ContainsKey(connName))
            {
                var connstr = "Data Source=" + Setting.Current.SQLiteDbPath.CombinePath(connName + ".db;Migration=On");
                WriteLog("自动为[{0}]设置SQLite连接字符串:{1}", connName, connstr);
                AddConnStr(connName, connstr, null, "SQLite");
            }

            _ConnStr = ConnStrs[connName];
            if (_ConnStr.IsNullOrEmpty())
            {
                throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            }

            //Queue = new EntityQueue(this);
        }
Example #3
0
File: DAL.cs Project: zzmzaizai/X
        /// <summary>构造函数</summary>
        /// <param name="connName">配置名</param>
        private DAL(String connName)
        {
            _ConnName = connName;

            //if (!ConnStrs.ContainsKey(connName)) throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            if (!ConnStrs.ContainsKey(connName))
            {
                var set    = Setting.Current;
                var dbpath = set.SQLiteDbPath;
                if (dbpath.IsNullOrEmpty())
                {
                    dbpath = ".";
                    if (Runtime.IsWeb)
                    {
                        if (!Environment.CurrentDirectory.Contains("iisexpress") ||
                            !Environment.CurrentDirectory.Contains("Web"))
                        {
                            dbpath = "..\\Data";
                        }
                        else
                        {
                            dbpath = "~\\App_Data";
                        }
                    }
                    set.SQLiteDbPath = dbpath;
                    set.Save();
                }
                var connstr = "Data Source=" + dbpath.GetFullPath().CombinePath(connName + ".db");
                WriteLog("自动为[{0}]设置连接字符串:{1}", connName, connstr);
                AddConnStr(connName, connstr, null, "SQLite");
            }

            _ConnStr = ConnStrs[connName].ConnectionString;
            if (String.IsNullOrEmpty(_ConnStr))
            {
                throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            }

            Queue = new EntityQueue {
                Dal = this
            };
        }
Example #4
0
        /// <summary>构造函数</summary>
        /// <param name="connName">配置名</param>
        private DAL(String connName)
        {
            _ConnName = connName;

            //if (!ConnStrs.ContainsKey(connName)) throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            if (!ConnStrs.ContainsKey(connName))
            {
                var connstr = "Data Source=" + Setting.Current.SQLiteDbPath.CombinePath(connName + ".db;Migration=On");
                WriteLog("自动为[{0}]设置SQLite连接字符串:{1}", connName, connstr);
                AddConnStr(connName, connstr, null, "SQLite");
            }

            _ConnStr = ConnStrs[connName];
            if (_ConnStr.IsNullOrEmpty())
            {
                throw new XCodeException("请在使用数据库前设置[" + connName + "]连接字符串");
            }

            Queue = new EntityQueue(this);
        }