Ejemplo n.º 1
0
        /// <summary>
        /// Internal Extendable method: 创建实体对象
        /// </summary>
        /// <param name="objectAccessor">实体对象访问器</param>
        /// <param name="tableMapper">Table元数据解析器</param>
        /// <param name="reader">数据流</param>
        /// <param name="columnNames">查询结果列的数组</param>
        /// <returns>实体对象</returns>
        internal static object CreateEntity(this ObjectAccessor objectAccessor, ITableMapper tableMapper, IDataReader reader, string[] columnNames)
        {
            //创建对象
            object entity = objectAccessor.CreateInstance();

            //读取DataReader当前行,为entity各个属性赋值
            objectAccessor.Fill(tableMapper.GetColumnMappers(), reader, columnNames, entity);
            //返回对象
            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建表
        /// </summary>
        /// <param name="dbHelper">操作数据库的Helper</param>
        /// <param name="commandTreeFactory">创建CommandTree的工厂</param>
        /// <param name="tableMapper">Table元数据解析器</param>
        public int CreateTable(DbHelper dbHelper, ICommandTreeFactory commandTreeFactory, ITableMapper tableMapper)
        {
            //获取TableHeader
            ITableHeader tableHeader = tableMapper.Header;
            //获取ColumnNodes
            IEnumerable <IColumnNode> columnNodes = tableMapper.GetColumnMappers().Select(m => m.ToColumnNode());
            //获取建表语句生成树
            ICommandTree buildTableTree = commandTreeFactory.GetBuildTableTree(tableHeader.SchemaName, tableHeader.TableName, columnNodes);

            //创建建表语句并执行
            return(dbHelper.ExecuteUpdate(buildTableTree.Compile()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 为当前实体所Mapping的Table添加没有添加的列
        /// </summary>
        /// <param name="dbHelper">操作数据库的Helper对象</param>
        /// <param name="commandTreeFactory">创建CommandTree的工厂</param>
        /// <param name="tableMapper">Table元数据解析器</param>
        public void AlterTableAddColumns(DbHelper dbHelper, ICommandTreeFactory commandTreeFactory, ITableMapper tableMapper)
        {
            //获取当前实体元数据解析器中某些属性Mapping的Column未包含在Table中的属性对应的ColumnMapper,并转换获取Column节点
            string[]      columnNames = this.GetColumns(dbHelper, tableMapper.Header).ToArray();
            IColumnNode[] columnNodes = (from columnMapper
                                         in tableMapper.GetColumnMappers()
                                         where !columnNames.Contains(columnMapper.ColumnName)
                                         select columnMapper.ToColumnNode()).ToArray();
            //若实体元数据解析器中所有属性Mapping的列都在当前Table中,直接退出
            if (columnNodes.Length == 0)
            {
                return;
            }
            //获取TableHeader
            ITableHeader tableHeader = tableMapper.Header;
            //创建Alter Table Columns语句生成树
            ICommandTree alterTableAddColumnsTree = commandTreeFactory.GetAlterTableAddColumnsTree(tableHeader.SchemaName, tableHeader.TableName, columnNodes);

            //生成并执行Alter Table Columns语句,为当前实体Mapping的Table添加为注册的列
            dbHelper.ExecuteUpdate(alterTableAddColumnsTree.Compile());
        }