/// <summary> /// 查询数据库并将第一个结果集填充实体类型 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">要执行的查询</param> /// <param name="converter">实体转换器</param> /// <returns>实体集</returns> public static T[] ExecuteEntities <T>(this IDbExecutable query, Func <DataRow, T> converter) { var data = query.ExecuteDataTable(); return(data.GetRows().Select(dataItem => converter(dataItem)).ToArray()); }
/// <summary> /// 查询数据库并将第一个结果集填充实体类型 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="query">要执行的查询</param> /// <param name="converter">实体转换器</param> /// <returns>实体集</returns> public static T[] ExecuteEntities <T>(this IDbExecutable query, IEntityConverter <T> converter) { var data = query.ExecuteDataTable(); return(data.GetRows().Select(dataItem => dataItem.ToEntity(converter)).ToArray()); }
/// <summary> /// 执行查询并将第一个结果集填充动态对象列表 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>查询结果</returns> public static dynamic[] ExecuteDynamics(this IDbExecutable query) { var data = query.ExecuteDataTable(); return(ToDynamics(data)); }
/// <summary> /// 执行查询并将第一行数据数据转换为 DataRowView 返回 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>转换为 DataRowView 的数据集合</returns> public static DataRowView ExecuteFirstDataRowView(this IDbExecutable query) { return(query.ExecuteDataTable().GetRowViews().FirstOrDefault()); }
/// <summary> /// 执行查询并将数据转换为 DataRowView 集合返回 /// </summary> /// <param name="query">要执行的查询</param> /// <returns>转换为 DataRowView 的数据集合</returns> public static IEnumerable <DataRowView> ExecuteDataRowViews(this IDbExecutable query) { return(query.ExecuteDataTable().GetRowViews()); }
/// <summary> /// 执行查询并返回第一列数据 /// </summary> /// <typeparam name="T">列类型</typeparam> /// <param name="query">要执行的查询</param> /// <returns>第一列的数据</returns> public static T[] ExecuteFirstColumn <T>(this IDbExecutable query) { return(query.ExecuteDataTable().Column <T>()); }