我对 UniversalConverter 方法有疑问。从数据库接收到的行应该转移到实体中。所以必须将 row[pi.Name] 转换为实体类型。如何执行此操作?
public void GetRequestSummary(string UserName, string Password)
{
List<EducationRequest> requestSummary = new List<EducationRequest>();
OracleCommand command = new OracleCommand();
AddParameter(command, _usernamePN, DbType.String, UserName);
AddParameter(command, _passwordPN, DbType.String, Password);
AddOracleCursor(command, _curPN, OracleType.Cursor, ParameterDirection.Output);
command.CommandType = CommandType.StoredProcedure;
DataSet personaSet =
FillDataset(command, _GetRequestSummaryCmd);
DataTable personaTable =
personaSet.Tables[0];
var request = new EducationRequestSummary();
foreach (DataRow row in personaTable.Rows)
{
UniversalConverter(request, row);
}
//any implementation
}
public void UniversalConverter<T>(T entity, DataRow row)
{
foreach (var pi in typeof(T).GetProperties())
{
pi.SetValue(entity, row[pi.Name], null);
}
}