/// <summary> /// 获取类属性的设置值委托列表 /// </summary> /// <param name="type">Type</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertySetCallDict(Type type, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) { return(ExecutePropertySetCall(type, () => { return ReflectionGenericHelper.PropertySetCallDict(type, reflectionType); }, reflectionType)); }
/// <summary> /// 创建多 Sheet Excel 文档 /// </summary> /// <param name="excelPath">Excel 路径</param> /// <param name="sheetDataList">单元格数据,类型:WriteMultiSheet</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static bool ToExcel(string excelPath, List <object> sheetDataList, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) { bool result = ExcelHelper.ExecuteIWorkbookWrite(excelPath, (IWorkbook workbook) => { MethodInfo method = typeof(ExcelHelper).GetMethod("ToSheet", BindingFlags.Static | BindingFlags.NonPublic); foreach (object sheetData in sheetDataList) { IWriteMultiSheet excelMultiSheet = sheetData as IWriteMultiSheet; if (excelMultiSheet != null) { Type sheetType = ReflectionHelper.GetGenericType(sheetData.GetType()); MethodInfo generic = method.MakeGenericMethod(sheetType); generic.Invoke(ExcelHelper.Instance, new object[] { workbook, ReflectionHelper.GetPropertyValue(sheetData, sheetData.GetType().GetProperty("DataList")), excelMultiSheet.SheetName, excelMultiSheet.CellCallback, excelMultiSheet.SheetCallback, excelMultiSheet.IsHeader, excelMultiSheet.PropertyList, excelMultiSheet.PropertyContain, excelMultiSheet.PropertyMatchList, excelMultiSheet.ColumnValueFormat, reflectionType }); } } }); return(result); }
/// <summary> /// 获取类属性的设置值委托 /// </summary> /// <param name="type">Type</param> /// <param name="propertyName">属性名称</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertySetCall(Type type, string propertyName, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) { return(ExecutePropertySetCall(type, propertyName, () => { return ReflectionGenericHelper.PropertySetCall(type, type.GetProperty(propertyName), reflectionType); }, reflectionType)); }
/// <summary> /// 获取类属性的获取值委托 /// </summary> /// <param name="type">Type</param> /// <param name="propertyInfo">PropertyInfo</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertyGetCall(Type type, PropertyInfo propertyInfo, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) { return(ExecutePropertyGetCall(type, propertyInfo.Name, () => { return ReflectionGenericHelper.PropertyGetCall(type, propertyInfo, reflectionType); }, reflectionType)); }
/// <summary> /// 属性设置值委托 /// </summary> /// <param name="type">Type</param> /// <param name="propertyInfo">PropertyInfo</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertySetCall(Type type, PropertyInfo propertyInfo, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) { MethodInfo method = typeof(ReflectionGenericHelper).GetMethod("PropertySetCall", new Type[] { typeof(PropertyInfo), typeof(ReflectionTypeEnum) }); MethodInfo generic = method.MakeGenericMethod(type); return(generic.Invoke(ReflectionGenericHelper.Instance, new object[] { propertyInfo, reflectionType })); }
/// <summary> /// T 类型属性获取值委托列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static Dictionary <string, Func <T, object> > PropertyGetCallDict <T>(ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { if (reflectionType == ReflectionTypeEnum.Expression) { return(ExpressionPropertyGetCallDict <T>()); } return(EmitPropertyGetCallDict <T>()); }
/// <summary> /// T 类型索引器获取值委托 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <typeparam name="K">索引器参数类型</typeparam> /// <typeparam name="P">索引器返回类型</typeparam> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static Func <T, K, object> PropertyIndexGetCall <T, K, P>(ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { if (reflectionType == ReflectionTypeEnum.Expression) { return(ExpressionPropertyIndexGetCall <T, K, P>()); } return(EmitPropertyIndexGetCall <T, K, P>()); }
/// <summary> /// 获取类属性的设置值委托列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertySetCallDict <T>(ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { Type type = typeof(T); return(ExecutePropertySetCall(type, () => { return ReflectionGenericHelper.PropertySetCallDict <T>(reflectionType); }, reflectionType)); }
/// <summary> /// 获取类属性的设置值委托 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="propertyName">属性名称</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertySetCall <T>(string propertyName, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { Type type = typeof(T); return(ExecutePropertySetCall(type, propertyName, () => { return ReflectionGenericHelper.PropertySetCall <T>(type.GetProperty(propertyName), reflectionType); }, reflectionType)); }
/// <summary> /// 获取类属性的获取值委托 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="propertyInfo">PropertyInfo</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertyGetCall <T>(PropertyInfo propertyInfo, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { Type type = typeof(T); return(ExecutePropertyGetCall(type, propertyInfo.Name, () => { return ReflectionGenericHelper.PropertyGetCall <T>(propertyInfo, reflectionType); }, reflectionType)); }
/// <summary> /// 根据 XPath 返回实体数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="xmlDocument">XmlDocument</param> /// <param name="xPath">XPath 查询语句</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static T ToEntity <T>(XmlDocument xmlDocument, string xPath, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { XmlNode xmlNode = GetNode(xPath, xmlDocument); if (xmlNode != null) { return(XmlNodeToEntity <T>(xmlNode, null, null, reflectionType)); } return(null); }
/// <summary> /// 返回实体数据列表 /// </summary> /// <typeparam name="T">泛型实体对象</typeparam> /// <param name="xmlPath">Xml 路径</param> /// <param name="xPath">XPath 查询语句</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static List <T> ToEntityList <T>(string xmlPath, string xPath, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { List <T> dataList = null; ExecuteXmlDocument(xmlPath, (XmlDocument xmlDocument) => { dataList = ToEntityList <T>(xmlDocument, xPath, reflectionType); }); return(dataList); }
/// <summary> /// 复制数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <typeparam name="K">拥有索引器的实体类型</typeparam> /// <typeparam name="P">索引器参数类型,例:int</typeparam> /// <typeparam name="R">索引器返回类型,例:string</typeparam> /// <param name="originalData">原实体数据</param> /// <param name="propertyMatchList">属性匹配,例:new { ID = "UserID" }</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static T Copy <T, K, P, R>(K originalData, object propertyMatchList = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() where K : class { T t = ReflectionGenericHelper.New <T>(); Func <K, P, object> indexCall = ReflectionGenericHelper.PropertyIndexGetCall <K, P, R>(reflectionType); Dictionary <PropertyInfo, string> propertyMatchDict = InitPropertyMatchMapper(originalData.GetType(), typeof(T), propertyMatchList, null); foreach (var keyValueItem in propertyMatchDict) { P indexName = (P)Convert.ChangeType(keyValueItem.Value, typeof(P), CultureInfo.InvariantCulture); ReflectionHelper.SetPropertyValue(t, indexCall(originalData, indexName).ToString(), keyValueItem.Key); } return(t); }
/// <summary> /// 复制数据 /// </summary> /// <param name="originalData">原实体数据</param> /// <param name="targetData">目标实体数据</param> /// <param name="propertyMatchList">属性匹配,例:new { ID = "UserID" }</param> /// <param name="propertyIgnore">忽略属性列表,例:new { ID = "" }</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic Copy(object originalData, object targetData, object propertyMatchList = null, object propertyIgnore = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) { Dictionary <PropertyInfo, string> propertyMatchDict = InitPropertyMatchMapper(originalData.GetType(), targetData.GetType(), propertyMatchList, propertyIgnore); dynamic propertyGetDict = ReflectionExtendHelper.PropertyGetCallDict(originalData.GetType(), reflectionType); dynamic propertySetDict = ReflectionExtendHelper.PropertySetCallDict(targetData.GetType(), reflectionType); object copyData = CopyData(targetData, propertySetDict, propertyGetDict, propertyMatchDict, originalData, propertyMatchList, propertyIgnore, reflectionType); return(Convert.ChangeType(copyData, targetData.GetType())); }
private static List <T> DataReaderToEntityList <T>(DbCommand command, object propertyMatchList = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { List <T> dataList = new List <T>(); bool initStatus = false; List <string> columnNameList = null; Dictionary <PropertyInfo, string> columnNameDict = null; using (DbDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection)) { dynamic propertySetDict = null; if (reflectionType != ReflectionTypeEnum.Original) { propertySetDict = ReflectionExtendHelper.PropertySetCallDict <T>(reflectionType); } if (dataReader.Read()) { if (!initStatus) { columnNameList = new List <string>(); for (int index = 0; index < dataReader.FieldCount; index++) { columnNameList.Add(dataReader.GetName(index)); } columnNameDict = InitDbToEntityMapper <T>(dataReader, propertyMatchList); initStatus = true; } dataList.Add(DataReaderToEntity <T>(dataReader, propertySetDict, columnNameList, columnNameDict)); } while (dataReader.Read()) { dataList.Add(DataReaderToEntity <T>(dataReader, propertySetDict, columnNameList, columnNameDict)); } } return(dataList); }
private static object ExecuteTransaction <T>(string connectionString, string dataBaseType, List <DataBaseTransactionItem> transactionItemList, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { DbConnection con = null; DbCommand command = null; DbTransaction transaction = null; try { object result = null; using (con = CreateDbConnection(connectionString, dataBaseType)) { transaction = con.BeginTransaction(); // 记录输出参数信息 Dictionary <string, object> outputParamDict = new Dictionary <string, object>(); foreach (DataBaseTransactionItem commandItem in transactionItemList) { Dictionary <string, object> parameterDict = CommonHelper.GetParameterDict(commandItem.ParameterList); // 如果需要使用之前的输出数据 if (commandItem.InputList != null && commandItem.InputList.Length > 0) { foreach (string inputParamItem in commandItem.InputList) { if (outputParamDict.ContainsKey(inputParamItem) && parameterDict.ContainsKey(inputParamItem)) { parameterDict[inputParamItem] = outputParamDict[inputParamItem]; } } } command = CreateDbCommand(con, command, commandItem.CommandText, parameterDict, null, CommandType.Text); command.Transaction = transaction; if (commandItem.ExecuteType == DataBaseExecuteTypeEnum.ExecuteNonQuery) { result = command.ExecuteNonQuery(); } else if (commandItem.ExecuteType == DataBaseExecuteTypeEnum.ExecuteScalar) { result = command.ExecuteScalar(); } else if (commandItem.ExecuteType == DataBaseExecuteTypeEnum.ToEntityList) { result = DataReaderToEntityList <T>(command, commandItem.PropertyMatchList, reflectionType); } else if (commandItem.ExecuteType == DataBaseExecuteTypeEnum.ToEntity) { List <T> dataList = DataReaderToEntityList <T>(command, commandItem.PropertyMatchList, reflectionType); if (dataList.Count > 0) { result = dataList[0]; } } // 如果输出参数不为空,则记录输出值 if (!string.IsNullOrEmpty(commandItem.OutputName)) { outputParamDict.Add(commandItem.OutputName, result); } } try { transaction.Commit(); } catch { transaction.Rollback(); throw; } } return(result); } catch { throw; } finally { if (command != null) { command.Dispose(); } } }
private static List <T> ReturnEntityList <T>(string connectionString, string dataBaseType, string commandText, Dictionary <string, object> parameterList, ref int pageCount, ref int totalCount, object propertyMatchList, string parameterPageCountName = "PageCount", string parameterTotalCountName = "TotalCount", CommandType commandType = CommandType.Text, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { List <T> dataList = null; Dictionary <string, object> outParameterList = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(parameterPageCountName)) { outParameterList.Add("@" + parameterPageCountName, 0); } if (!string.IsNullOrEmpty(parameterTotalCountName)) { outParameterList.Add("@" + parameterTotalCountName, 0); } if (string.IsNullOrEmpty(commandText) && DataBaseType == DataBaseTypeEnum.Sql) { commandText = SqlDataBaseItem.PaginationSql; } int commandPageCount = 0; int commandTotalCount = 0; ExecuteCommand(connectionString, dataBaseType, commandText, parameterList, outParameterList, commandType, (DbCommand command) => { dataList = DataReaderToEntityList <T>(command, propertyMatchList, reflectionType); if (!string.IsNullOrEmpty(parameterPageCountName)) { commandPageCount = (int)command.Parameters["@" + parameterPageCountName].Value; } if (!string.IsNullOrEmpty(parameterTotalCountName)) { commandTotalCount = (int)command.Parameters["@" + parameterTotalCountName].Value; } }); pageCount = commandPageCount; totalCount = commandTotalCount; return(dataList); }
/// <summary> /// 返回实体数据列表(事务) /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="connectionString">连接字符串</param> /// <param name="dataBaseType">数据库类型</param> /// <param name="transactionCommandList">DataBaseTransactionItem 列表</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static List <T> TransactionEntityList <T>(string connectionString, string dataBaseType, List <DataBaseTransactionItem> transactionCommandList, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { return((List <T>)ExecuteTransaction <T>(connectionString, dataBaseType, transactionCommandList, reflectionType)); }
/// <summary> /// 属性设置值委托 /// </summary> /// <param name="type">Type</param> /// <param name="propertyName">属性名称</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static dynamic PropertySetCall(Type type, string propertyName, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) { return(PropertySetCall(type, type.GetProperty(propertyName), reflectionType)); }
/// <summary> /// 实体数据列表批量导入 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="tableName">数据库表名称</param> /// <param name="dataList">实体类型数据列表</param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="propertyList">属性列表,如果指定,则按指定属性列表生成 DataTable 数据</param> /// <param name="propertyContain">是否包含,true 属性包含,flase 属性排除</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static bool EntityListBatchImport <T>(string tableName, List <T> dataList, object propertyMatchList = null, string[] propertyList = null, bool propertyContain = true, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { return(EntityListBatchImport <T>(null, tableName, dataList, propertyMatchList, propertyList, propertyContain, reflectionType)); }
/// <summary> /// 返回实体数据(事务) /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="connectionString">连接字符串</param> /// <param name="dataBaseType">数据库类型</param> /// <param name="transactionCommandList">DataBaseTransactionItem 列表</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static T TransactionEntity <T>(string connectionString, string dataBaseType, List <DataBaseTransactionItem> transactionCommandList, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { List <T> dataList = TransactionEntityList <T>(connectionString, dataBaseType, transactionCommandList, reflectionType); if (dataList.Count > 0) { return(dataList[0]); } return(null); }
/// <summary> /// 返回实体数据(事务) /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="transactionCommandList">DataBaseTransactionItem 列表</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static T TransactionEntity <T>(List <DataBaseTransactionItem> transactionCommandList, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { return(TransactionEntity <T>(null, null, transactionCommandList, reflectionType)); }
/// <summary> /// 返回实体数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="commandText">Sql 语句或者存储过程名称</param> /// <param name="parameterList">参数列表,new {} 或 Dictionary<string, object></param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="commandType">CommandType 枚举类型</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static T ToEntity <T>(string commandText, object parameterList = null, object propertyMatchList = null, CommandType commandType = CommandType.Text, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { return(ToEntity <T>(null, null, commandText, parameterList, propertyMatchList, commandType, reflectionType)); }
/// <summary> /// 返回实体数据列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="connectionString">连接字符串</param> /// <param name="dataBaseType">数据库类型</param> /// <param name="commandText">Sql 语句或者存储过程名称</param> /// <param name="parameterList">参数列表,new {} 或 Dictionary<string, object></param> /// <param name="pageCount">页总数,输出</param> /// <param name="totalCount">数据总数,输出</param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="parameterPageCountName">页总数参数名称,例如:PageCount</param> /// <param name="parameterTotalCountName">数据总数参数名称,例如:TotalCount</param> /// <param name="commandType">CommandType 枚举类型</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static List <T> ToEntityList <T>(string connectionString, string dataBaseType, string commandText, object parameterList, ref int pageCount, ref int totalCount, object propertyMatchList, string parameterPageCountName = "PageCount", string parameterTotalCountName = "TotalCount", CommandType commandType = CommandType.Text, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { Dictionary <string, object> parameterDict = CommonHelper.GetParameterDict(parameterList); return(ReturnEntityList <T>(connectionString, dataBaseType, commandText, parameterDict, ref pageCount, ref totalCount, propertyMatchList, parameterPageCountName, parameterTotalCountName, commandType, reflectionType)); }
/// <summary> /// T 类型属性设置值委托 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="propertyName">属性名称</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static Action <T, object> PropertySetCall <T>(string propertyName, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { return(PropertySetCall <T>(typeof(T).GetProperty(propertyName), reflectionType)); }
/// <summary> /// 实体数据列表批量导入 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="connectionString"></param> /// <param name="tableName">数据库表名称</param> /// <param name="dataList">实体类型数据列表</param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="propertyList">属性列表,如果指定,则按指定属性列表生成 DataTable 数据</param> /// <param name="propertyContain">是否包含,true 属性包含,flase 属性排除</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static bool EntityListBatchImport <T>(string connectionString, string tableName, List <T> dataList, object propertyMatchList = null, string[] propertyList = null, bool propertyContain = true, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { DataTable dataTable = DataTableHelper.ToDataTable <T>(dataList, propertyMatchList, propertyList, propertyContain, reflectionType); if (dataTable != null) { return(DataTableBatchImport(connectionString, tableName, dataTable)); } return(false); }
/// <summary> /// T 类型属性设置值委托 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="propertyInfo">PropertyInfo</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static Action <T, object> PropertySetCall <T>(PropertyInfo propertyInfo, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { if (reflectionType == ReflectionTypeEnum.Expression) { return(ExpressionPropertySetCall <T>(propertyInfo)); } return(EmitPropertySetCall <T>(propertyInfo)); }
private static List <T> ReturnEntityList <T>(string connectionString, string dataBaseType, string commandText, Dictionary <string, object> parameterList, object propertyMatchList, CommandType commandType = CommandType.Text, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { List <T> dataList = null; ExecuteCommand(connectionString, dataBaseType, commandText, parameterList, null, commandType, (DbCommand command) => { dataList = DataReaderToEntityList <T>(command, propertyMatchList, reflectionType); }); return(dataList); }
/// <summary> /// 返回实体数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="connectionString">连接字符串</param> /// <param name="dataBaseType">数据库类型</param> /// <param name="commandText">Sql 语句或者存储过程名称</param> /// <param name="parameterList">参数列表,new {} 或 Dictionary<string, object></param> /// <param name="propertyMatchList">属性匹配,Dictionary<string, object> 或 new {}</param> /// <param name="commandType">CommandType 枚举类型</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static T ToEntity <T>(string connectionString, string dataBaseType, string commandText, object parameterList = null, object propertyMatchList = null, CommandType commandType = CommandType.Text, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { List <T> dataList = ToEntityList <T>(connectionString, dataBaseType, commandText, parameterList, propertyMatchList, commandType, reflectionType); if (dataList.Count > 0) { return(dataList[0]); } return(null); }
/// <summary> /// 返回实体数据列表 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="commandText">Sql 语句或者存储过程名称</param> /// <param name="parameterList">参数列表,new {} 或 Dictionary<string, object></param> /// <param name="pageCount">页总数,输出</param> /// <param name="totalCount">数据总数,输出</param> /// <param name="propertyMatchList">属性匹配,,Dictionary<string, object> 或 new {}</param> /// <param name="parameterPageCountName">页总数参数名称,例如:PageCount</param> /// <param name="parameterTotalCountName">数据总数参数名称,例如:TotalCount</param> /// <param name="commandType">CommandType 枚举类型</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static List <T> ToEntityList <T>(string commandText, object parameterList, ref int pageCount, ref int totalCount, object propertyMatchList, string parameterPageCountName = "PageCount", string parameterTotalCountName = "TotalCount", CommandType commandType = CommandType.Text, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { return(ToEntityList <T>(null, null, commandText, parameterList, ref pageCount, ref totalCount, propertyMatchList, parameterPageCountName, parameterTotalCountName, commandType, reflectionType)); }