/// <summary> /// 读取单条记录(泛型) /// </summary> /// <typeparam name="TEntity">返回结果类型</typeparam> /// <param name="commandText">执行语句</param> /// <param name="parameters">参数列表</param> /// <returns>返回结果</returns> public TEntity QuerySingleEntity <TEntity>(string commandText, IDictionary <string, object> parameters = null) where TEntity : class, new() { Func <DbCommand, TEntity> excute = (dbCommand) => { using (IDataReader reader = dbCommand.ExecuteReader()) { var converter = new DbReaderConverter <TEntity>(reader); if (reader.Read()) { return(converter.CreateItemFromRow()); } return(null); } }; return(CreateDbCommondAndExcute(commandText, parameters, excute)); }
/// <summary> /// 读取列表数据(泛型) /// </summary> /// <typeparam name="TEntity">返回结果类型</typeparam> /// <param name="commandText">执行语句</param> /// <param name="parameters">参数列表</param> /// <returns>返回结果</returns> public List <TEntity> QueryListEntity <TEntity>(string commandText, IDictionary <string, object> parameters = null) where TEntity : class, new() { Func <DbCommand, List <TEntity> > excute = (dbCommand) => { using (IDataReader reader = dbCommand.ExecuteReader()) { var result = new List <TEntity>(); var converter = new DbReaderConverter <TEntity>(reader); while (reader.Read()) { var item = converter.CreateItemFromRow(); result.Add(item); } return(result); } }; return(CreateDbCommondAndExcute(commandText, parameters, excute)); }