Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

No commit message

  • Loading branch information...
commit 119359b36adc58ac51e65a5f0d01726aa9a0011a 1 parent c11b7cf
@Ivony authored
View
25 Sources/Ivony.Data/DataSetExtensions.cs
@@ -23,5 +23,30 @@ public static IEnumerable<DataRowView> View( this DataTable table )
return table.DefaultView.Cast<DataRowView>();
}
+
+ /// <summary>
+ /// 获取第一列数据
+ /// </summary>
+ /// <typeparam name="T">列数据类型</typeparam>
+ /// <param name="table">数据对象</param>
+ /// <returns></returns>
+ public static IEnumerable<T> Column<T>( this DataTable table )
+ {
+ return table.Rows.Cast<DataRow>().Select( item => item.Field<T>( 0 ) );
+ }
+
+ /// <summary>
+ /// 获取指定列数据
+ /// </summary>
+ /// <typeparam name="T">列数据类型</typeparam>
+ /// <param name="table">数据对象</param>
+ /// <param name="columnName">列名</param>
+ /// <returns></returns>
+ public static IEnumerable<T> Column<T>( this DataTable table, string columnName )
+ {
+ return table.Rows.Cast<DataRow>().Select( item => item.Field<T>( columnName ) );
+ }
+
+
}
}
View
7 Sources/Ivony.Data/LegacyExtensions.cs
@@ -24,7 +24,7 @@ public static object ExecuteScalar( this DbUtility dbUtility, string template, p
public static int ExecuteNonQuery( this DbUtility dbUtility, string template, params object[] args )
{
- return dbUtility.ExecuteNonQuery( template, args );
+ return dbUtility.NonQuery( template, args );
}
public static DataRow ExecuteSingleRow( this DbUtility dbUtility, string template, params object[] args )
@@ -32,10 +32,5 @@ public static DataRow ExecuteSingleRow( this DbUtility dbUtility, string templat
return dbUtility.FirstRow( template, args );
}
- public static DataTable ExecuteData( this DbUtility dbUtility, string template, params object[] args )
- {
- return dbUtility.Data( template, args );
- }
-
}
}
View
11 Sources/Ivony.Data/TemplateExtensions.cs
@@ -49,6 +49,17 @@ public static object Scalar( this DbUtility dbUtility, string commandText, param
}
/// <summary>
+ /// 执行查询,并返回首行首列
+ /// </summary>
+ /// <param name="commandText">查询字符串模板</param>
+ /// <param name="parameters">查询字符串参数</param>
+ /// <returns></returns>
+ public static T Scalar<T>( this DbUtility dbUtility, string commandText, params object[] parameters )
+ {
+ return (T) Scalar( dbUtility, commandText, parameters );
+ }
+
+ /// <summary>
/// 执行查询,并返回首行
/// </summary>
/// <param name="commandText">查询字符串模板</param>
Please sign in to comment.
Something went wrong with that request. Please try again.