I'm having a problem with one of my methods taking 4-5 minutes to initialize ~17,000 poco objects and filling a list with them. I'm trying to get away from paging the data in the query, so initializing the ~17,000 is needed. We are using an Oracle DB and the Microsoft.Practices.EnterpriseLibrary to call the DB. Not sure if that info is relevant but just in case. I'm using ExecuteReader method's reader object to set the Poco class's 60 properties. I'm not really sure why it is taking so long. The query take about 3-5 seconds to execute. So any advice on how I can change my code to speed things up would be greatly appreciated. Also, someone told me that the query is executed on the reader.Read() call and not the ExecuteReader() call. I don't think that's correct, but if someone know's if it is could you clue me in? Thanks again.
POCO Class
public class BaseWorkItem : ITransactionWorkItem
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
....
public ITransactionWorkItem SetValues(IDataReader reader)
{
Prop1 = reader["Prop1"] != DBNull.Value ?
Convert.ToInt32(reader["Prop1"]) : -1;
Prop2 = reader["Prop2"] != DBNull.Value ?
reader["Prop2"].ToString() : "";
....
return this;
}
}
DataAccess & Initialization Methods
static IEnumerable<ITransactionWorkItem> GetQueue_WorkItems<T>(IDataReader reader)
where T : ITransactionWorkItem, new()
{
if (reader.IsNotNull())
{
while (reader.Read())
{
yield return (T)(new T().SetValues(reader));
}
}
}
public static List<ITransactionWorkItem> GetItems(int param1, int param2,
int param3, int param4)
{
Database oracle = null;
IDataReader reader = null;
var items = new List<ITransactionWorkItem>();
oracle = Oracle.GetDatabase();
using (reader = oracle.ExecuteReader("SomeProcedureName", param1, param2,
param3, param4, null))
{
items.AddRange(GetQueue_WorkItems<BaseWorkItem>(reader));
}
return items;
}