public DataRow LoadDataRow(object[] values, LoadOption loadOption)
{
long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataTable.LoadDataRow|API> {0}, loadOption={1}", ObjectID, loadOption);
try
{
Index indextoUse = null;
if (_primaryKey != null)
{
if (loadOption == LoadOption.Upsert)
{
// CurrentVersion, and Deleted
if (_loadIndexwithCurrentDeleted == null)
{
_loadIndexwithCurrentDeleted = _primaryKey.Key.GetSortIndex(DataViewRowState.CurrentRows | DataViewRowState.Deleted);
Debug.Assert(_loadIndexwithCurrentDeleted != null, "loadIndexwithCurrentDeleted should not be null");
if (_loadIndexwithCurrentDeleted != null)
{
_loadIndexwithCurrentDeleted.AddRef();
}
}
indextoUse = _loadIndexwithCurrentDeleted;
}
else
{
// CurrentVersion, and Deleted : OverwriteRow, PreserveCurrentValues
if (_loadIndexwithOriginalAdded == null)
{
_loadIndexwithOriginalAdded = _primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added);
Debug.Assert(_loadIndexwithOriginalAdded != null, "loadIndexwithOriginalAdded should not be null");
if (_loadIndexwithOriginalAdded != null)
{
_loadIndexwithOriginalAdded.AddRef();
}
}
indextoUse = _loadIndexwithOriginalAdded;
}
// not expecting LiveIndexes to clear the index we use between calls to LoadDataRow
Debug.Assert(2 <= indextoUse.RefCount, "bad indextoUse.RefCount");
}
if (_inDataLoad && !AreIndexEventsSuspended)
{
// we do not want to fire any listchanged in new Load/Fill
SuspendIndexEvents();// so suspend events here(not suspended == table already has some rows initially)
}
DataRow dataRow = LoadRow(values, loadOption, indextoUse);// if indextoUse == null, it means we dont have PK,
// so LoadRow will take care of just adding the row to end
return dataRow;
}
finally
{
DataCommonEventSource.Log.ExitScope(logScopeId);
}
}