using Common.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Common.Database
{
///
/// 数据库数据转换拓展
///
public static class DbDataConvertExtensions
{
///
/// 将 DataTable 转 List 集合
///
/// 返回值类型
/// DataTable
/// List{T}
public static List ToList(this DataTable dataTable)
{
return dataTable.ToList(typeof(List)) as List;
}
///
/// 将 DataTable 转 List 集合
///
/// 返回值类型
/// DataTable
/// List{T}
public static async Task> ToListAsync(this DataTable dataTable)
{
var list = await dataTable.ToListAsync(typeof(List));
return list as List;
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// DataSet
/// 元组类型
public static List ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List));
return tuple[0] as List;
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// 元组元素类型
/// DataSet
/// 元组类型
public static (List list1, List list2) ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List), typeof(List));
return (tuple[0] as List, tuple[1] as List);
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// DataSet
/// 元组类型
public static (List list1, List list2, List list3) ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List), typeof(List), typeof(List));
return (tuple[0] as List, tuple[1] as List, tuple[2] as List);
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// DataSet
/// 元组类型
public static (List list1, List list2, List list3, List list4) ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List), typeof(List), typeof(List), typeof(List));
return (tuple[0] as List, tuple[1] as List, tuple[2] as List, tuple[3] as List);
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// DataSet
/// 元组类型
public static (List list1, List list2, List list3, List list4, List list5) ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List), typeof(List), typeof(List), typeof(List), typeof(List));
return (tuple[0] as List, tuple[1] as List, tuple[2] as List, tuple[3] as List, tuple[4] as List);
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// DataSet
/// 元组类型
public static (List list1, List list2, List list3, List list4, List list5, List list6) ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List), typeof(List), typeof(List), typeof(List), typeof(List), typeof(List));
return (tuple[0] as List, tuple[1] as List, tuple[2] as List, tuple[3] as List, tuple[4] as List, tuple[5] as List);
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// DataSet
/// 元组类型
public static (List list1, List list2, List list3, List list4, List list5, List list6, List list7) ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List), typeof(List), typeof(List), typeof(List), typeof(List), typeof(List), typeof(List));
return (tuple[0] as List, tuple[1] as List, tuple[2] as List, tuple[3] as List, tuple[4] as List, tuple[5] as List, tuple[6] as List);
}
///
/// 将 DataSet 转 元组
///
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// 元组元素类型
/// DataSet
/// 元组类型
public static (List list1, List list2, List list3, List list4, List list5, List list6, List list7, List list8) ToList(this DataSet dataSet)
{
var tuple = dataSet.ToList(typeof(List), typeof(List), typeof(List), typeof(List), typeof(List), typeof(List), typeof(List), typeof(List));
return (tuple[0] as List, tuple[1] as List, tuple[2] as List, tuple[3] as List, tuple[4] as List, tuple[5] as List, tuple[6] as List, tuple[7] as List);
}
///
/// 将 DataSet 转 特定类型
///
/// DataSet
/// 特定类型集合
/// List{object}
public static List