本文整理汇总了C#中DbHelper.ExecuteReaderExt方法的典型用法代码示例。如果您正苦于以下问题:C# DbHelper.ExecuteReaderExt方法的具体用法?C# DbHelper.ExecuteReaderExt怎么用?C# DbHelper.ExecuteReaderExt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbHelper
的用法示例。
在下文中一共展示了DbHelper.ExecuteReaderExt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOne
public User GetOne(Where @where, string fields) {
using (SqlCommand command = new DbHelper().Command) {
User user = new User();
string sql = $"select top 1 {fields} from {Table} where {where.Result};";
IDataReader reader = command.ExecuteReaderExt(sql, where);
if (reader.Read()) {
user = ReaderModel(reader, fields);
}
return user;
}
}
示例2: GetList
public List<User> GetList(Where where, string fields, string orderby, int pageIndex, int pageSize) {
string sqlBase = $"select {fields} from {Table} where {@where.Result} ";
const string sqlPageBase = @"select * from(
select *,ROW_NUMBER() OVER (ORDER BY {1}) as rank from ({0})a
)as t where t.rank between {2} and {3}";
int startPageIndex = (pageIndex - 1)*pageSize + 1;
int endPageIndex = pageIndex*pageSize;
string sqlPage = string.Format(sqlPageBase, sqlBase, orderby, startPageIndex, endPageIndex);
using (SqlCommand command = new DbHelper().Command) {
List<User> users = new List<User>();
IDataReader reader = command.ExecuteReaderExt(sqlPage, where);
while (reader.Read()) {
User user = ReaderModel(reader, fields);
users.Add(user);
}
return users;
}
}
示例3: GetRecordCount
public int GetRecordCount(Where @where) {
string sql = $"select count(1) total from {Table} where {where.Result};";
using (SqlCommand command = new DbHelper().Command) {
command.CommandText = sql;
command.CommandType = CommandType.Text;
IDataReader reader = command.ExecuteReaderExt(sql, where);
if (reader.Read()) {
object countObj = reader["total"];
return countObj.ToInt();
}
return 0;
}
}