Beispiel #1
0
        /// <summary>
        /// 更新数据库版本
        /// </summary>
        /// <param name="up"></param>
        protected void UPDBVersion(SZORM_Upgrade up)
        {
            if (up.Version <= dbVersion)
            {
                throw new Exception("更新后的版本必须大于现有版本");
            }

            up.UPTime = DateTime.Now;
            SZORM_Upgrades.Add(up);

            dbVersion = up.Version;
        }
Beispiel #2
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();
        }