/// <summary> /// 将指定的集合转换为数据表格。 /// </summary> /// <typeparam name="TEntity">实体的数据类型。</typeparam> /// <param name="collection">集合。</param> /// <param name="totalCount">数据的总行数。</param> /// <returns>返回一张表。</returns> public static AoiteTable ToTable <TEntity>(this IEnumerable <TEntity> collection, long totalCount = 0) { if (collection == null) { throw new ArgumentNullException("collection"); } var mp = TypeMapper.Instance <TEntity> .Mapper; AoiteTable table = new AoiteTable() { TableName = mp.Name }; foreach (var p in mp.Properties) { table.Columns.Add(p.Name, p.Property.PropertyType); } table.BeginLoadData(); foreach (var item in collection) { var row = table.NewRow(); mp.From(item).To(row); table.Rows.Add(row); } table.EndLoadData(); table.TotalRowCount = totalCount > 0 ? totalCount : table.Rows.Count; return(table); }
/// <summary> /// 执行查询,并返回一张表。 /// </summary> /// <param name="dbCommand">数据库命令。</param> /// <param name="dataAdpater">数据源适配器。</param> /// <returns>返回一张表。</returns> public static AoiteTable ExecuteTable(this DbCommand dbCommand, DbDataAdapter dataAdpater) { if (dbCommand == null) { throw new ArgumentNullException("command"); } if (dataAdpater == null) { throw new ArgumentNullException("dataAdpater"); } AoiteTable table = new AoiteTable(); dataAdpater.Fill(table); table.TotalRowCount = table.Rows.Count; return(table); }