我刚刚了解到,我的应用程序性能损失的很大一部分来自于处理数据集中的数据.DataTable:
任何想法? (我不能停止使用DS,它在应用程序中根深蒂固)
大多数情况下,我有1行,500列以上和200或更多计算列
private void AddComputedColumns()
{
Hashtable oldRowStatus = new Hashtable();
int i = m_RowCountBeforeNextRetrive;
for (i = m_RowCountBeforeNextRetrive; i < m_Data.Tables[0].Rows.Count; i++)
{
DataRow dr = m_Data.Tables[0].Rows[i];
oldRowStatus[dr.GetHashCode()] = new object[] { dr.RowState, dr.RowError };
}
// add the computed columns
if (m_BoComputedColumns.Count > 0)
{
foreach (AOColumn col in m_BoComputedColumns)
{
if (col.Value == null)
col.Value = DBNull.Value;
DataColumn dc;
if (m_RowCountBeforeNextRetrive == 0)
{
if (!m_Data.Tables[0].Columns.Contains(col.Name))
{
dc = m_Data.Tables[0].Columns.Add(col.Name, col.GetDataType());
dc.ReadOnly = false;
dc.ExtendedProperties.Add("IsComputed", true);
SetValueToComputedColumns(col, dc);
}
else
SetValueToComputedColumns(col, m_Data.Tables[0].Columns[col.Name]);
}
else
{
if (m_Data.Tables[0].Columns.Contains(col.Name))
SetValueToComputedColumns(col, m_Data.Tables[0].Columns[col.Name]);
}
}
}
for (i = m_RowCountBeforeNextRetrive; i < m_Data.Tables[0].Rows.Count; i++)
{
DataRow dr = m_Data.Tables[0].Rows[i];
object[] tmp = (object[])oldRowStatus[dr.GetHashCode()];
if ((DataRowState)tmp[0] == DataRowState.Unchanged && ((string)tmp[1]).Length == 0)
dr.AcceptChanges();
}
}
private void SetValueToComputedColumns(AOColumn col, DataColumn dc)
{
int i = m_RowCountBeforeNextRetrive;
for(i = m_RowCountBeforeNextRetrive; i < m_Data.Tables[0].Rows.Count; i++)
{
DataRow dr = m_Data.Tables[0].Rows[i];
dr[dc] = col.Value;
_syncedRowsList[i] = false;
}
}