public QueryEnumerator(InternalAdoSession adoSession, DbCommandFactor commandFactor)
            {
                this._adoSession      = adoSession;
                this._commandFactor   = commandFactor;
                this._objectActivator = commandFactor.ObjectActivator;

                this._reader = null;

                this._current     = default(T);
                this._hasFinished = false;
                this._disposed    = false;
            }
示例#2
0
        private void Init(IsolationLevel il)
        {
            _il = il;
            _dbDatabaseProvider = DatabaseProviderFactory.CreateDatabaseProvider(_dbType);

            //开始缓存数据结构,并初始化dbset
            _typeDescriptors = TypeDescriptors.GetTypeDescriptors(this);
            //初始化数据链接
            InitDb();
            //初始化数据库结构
            InternalAdoSession.BeginTransaction(_il);
        }
示例#3
0
        public DbContext(string connStr, IDatabaseProvider databaseProvider, IsolationLevel il = IsolationLevel.ReadCommitted)
        {
            _il = il;
            _dbConnectionStr = connStr;
            var newDatabase = DatabaseProviderFactory.CreateDatabaseProvider("", databaseProvider);

            _dbDatabaseProvider = newDatabase;
            _dbType             = newDatabase.DatabaseType;

            //开始缓存数据结构,并初始化dbset
            _typeDescriptors = TypeDescriptors.GetTypeDescriptors(this);
            //初始化数据链接
            InitDb();
            //初始化数据库结构
            InternalAdoSession.BeginTransaction(_il);
        }
示例#4
0
        private void Init(string ConnectionStr, string ProviderName, IsolationLevel il)
        {
            _il = il;
            Checks.NotNull(ConnectionStr, "ConnectionStr");
            Checks.NotNull(ProviderName, "ProviderName");
            //开始初始化
            _dbConfig = new DbConfig();
            _dbConfig.ConnectionStr = ConnectionStr;
            _dbConfig.ProviderName  = ProviderName;

            //开始缓存数据结构,并初始化dbset
            _typeDescriptors = TypeDescriptors.GetTypeDescriptors(this);

            this._dbContextServiceProvider = DbContextServiceProviderFactory.CreateDbConnection(_dbConfig);
            //初始化数据链接
            InitDb();
            //初始化数据库结构
            InternalAdoSession.BeginTransaction(_il);
        }
示例#5
0
        public override string ToString()
        {
            DbCommandFactor commandFactor = this.GenerateCommandFactor();

            return(InternalAdoSession.AppendDbCommandInfo(commandFactor.CommandText, commandFactor.Parameters));
        }
 public static IEnumerator <T> CreateEnumerator <T>(InternalAdoSession adoSession, DbCommandFactor commandFactor)
 {
     return(new QueryEnumerator <T>(adoSession, commandFactor));
 }
示例#7
0
        private void CreateTable()
        {
            //初始化所有的属性
            InternalAdoSession.BeginTransaction();
            //初始化库
            int i = 0;

            _dbStructCheck = this._dbDatabaseProvider.CreateStructureCheck();
            List <TableModel> TableModels = _dbStructCheck.TableList(this);

            foreach (var typeDescriptor in _typeDescriptors)
            {
                //如果是视图就不检查
                var __typeDescriptor = typeDescriptor.Value;
                if (__typeDescriptor.SZTableAttribute.IsView)
                {
                    continue;
                }
                bool __tablehas = false;
                foreach (var item in TableModels)
                {
                    if (__typeDescriptor.Table.Name.ToUpper() == item.Name.ToUpper())
                    {
                        //如果存在
                        __tablehas = true;
                        //就去检查所有的字段是否一致,
                        List <ColumnModel> ColumnModels = _dbStructCheck.ColumnList(this, item.Name);
                        foreach (var item1 in __typeDescriptor.MappingMemberDescriptors)
                        {
                            bool __fieldhas = false;
                            var  itemMember = item1.Value;
                            //itemMember.
                            foreach (var column in ColumnModels)
                            {
                                if (column.Name.ToUpper() == itemMember.Column.Name.ToUpper())
                                {
                                    //开始比对,是否一样
                                    var columnType = GetColumn(itemMember);
                                    if (itemMember.SZColumnAttribute.Required != column.Required ||
                                        columnType.ColumnFullType != column.ColumnFullType)
                                    {
                                        _dbStructCheck.ColumnEdit(this, __typeDescriptor.Table.Name, GetColumn(itemMember));
                                    }
                                    __fieldhas = true;
                                    break;
                                }
                            }
                            if (!__fieldhas)
                            {
                                //如果不存在字段则添加
                                _dbStructCheck.ColumnAdd(this, __typeDescriptor.Table.Name, GetColumn(itemMember));
                            }
                        }
                    }
                }
                if (!__tablehas)
                {
                    //如果不存在
                    TableModel table = new TableModel();
                    table.Name = __typeDescriptor.Table.Name;
                    foreach (var item in __typeDescriptor.MappingMemberDescriptors)
                    {
                        table.Columns.Add(GetColumn(item.Value));
                    }

                    _dbStructCheck.CreateTable(this, table);
                    i++;
                }
            }
            InternalAdoSession.CommitTransaction();
            //开始更新数据库
            var uplist = SZORM_Upgrades.AsQuery().OrderByDesc(o => o.Version).Take(1).ToList();

            if (uplist.Any())
            {
                dbVersion = uplist[0].Version;
            }
            else
            {
                SZORM_Upgrade up = new SZORM_Upgrade();
                up.UPTime    = DateTime.Now;
                up.Version   = 0;
                up.UPContent = "首次创建数据库.";
                UPDBVersion(up);
                _internalAdoSession.BeginTransaction();
                Initialization();
                _internalAdoSession.CommitTransaction();
            }
            _internalAdoSession.BeginTransaction();
            UpdataDBExce();
            _internalAdoSession.CommitTransaction();
        }