{
_table = table;
_rowId = rowId;
+ rowError = String.Empty;
}
#endregion // Constructors
/// </summary>
public bool HasErrors {
get {
- if (RowError != string.Empty)
+ if (!string.IsNullOrEmpty (RowError))
return true;
foreach (String columnError in ColumnErrors) {
- if (columnError != null && columnError != string.Empty)
+ if (!string.IsNullOrEmpty (columnError))
return true;
}
return false;
public object this [string columnName] {
get { return this [columnName, DataRowVersion.Default]; }
set {
- DataColumn column = _table.Columns [columnName];
- if (column == null)
- throw new ArgumentException ("The column '" + columnName +
- "' does not belong to the table : " + _table.TableName);
+ DataColumn column = GetColumn (columnName);
this [column.Ordinal] = value;
}
}
/// </summary>
public object this [string columnName, DataRowVersion version] {
get {
- DataColumn column = _table.Columns [columnName];
- if (column == null)
- throw new ArgumentException ("The column '" + columnName +
- "' does not belong to the table : " + _table.TableName);
+ DataColumn column = GetColumn (columnName);
return this [column.Ordinal, version];
}
}
/// </summary>
public string RowError {
get { return rowError; }
- set { rowError = value; }
+ set { rowError = value ?? string.Empty; }
}
internal int IndexFromVersion (DataRowVersion version)
if (index >= 0)
return index;
- throw new VersionNotFoundException (String.Format ("There is no {0} data to accces.", version));
+ throw new VersionNotFoundException (String.Format ("There is no {0} data to access.", version));
}
internal DataRowVersion VersionFromIndex (int index)
/// </summary>
public bool IsNull (string columnName)
{
- return IsNull (Table.Columns [columnName]);
+ return IsNull (GetColumn (columnName));
}
/// <summary>
/// </summary>
public bool IsNull (DataColumn column, DataRowVersion version)
{
+ if (column == null)
+ throw new ArgumentNullException ("column");
+
+ // use the expresion if there is one
+ if (column.Expression != String.Empty) {
+ // FIXME: how does this handle 'version'?
+ // TODO: Can we avoid the Eval each time by using the cached value?
+ object o = column.CompiledExpression.Eval (this);
+ return o == null && o == DBNull.Value;
+ }
+
return column.DataContainer.IsNull (IndexFromVersion (version));
}
/// </summary>
public void SetParentRow (DataRow parentRow, DataRelation relation)
{
- if (_table == null || parentRow.Table == null)
+ if (_table == null || (parentRow != null && parentRow.Table == null))
throw new RowNotInTableException ("This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.");
if (parentRow != null && _table.DataSet != parentRow.Table.DataSet)
BeginEdit();
IEnumerable relations;
- if (relation == null)
- relations = _table.ParentRelations;
- else
+ if (relation != null) {
+ if (parentRow != null && relation.ParentColumns [0].Table != parentRow.Table)
+ throw new InvalidConstraintException (string.Format ("Parent belongs to table {0} but relation is for table {1}", parentRow.Table, relation.ParentColumns [0].Table));
relations = new DataRelation [] { relation };
+ } else {
+ relations = _table.ParentRelations;
+ }
foreach (DataRelation rel in relations) {
DataColumn [] childCols = rel.ChildColumns;
for (int i = 0; i < parentCols.Length; i++) {
if (parentRow == null) {
childCols [i].DataContainer [Proposed] = DBNull.Value;
- } else {
+ } else if (parentCols [i].Table == parentRow.Table) {
int defaultIdx = parentRow.IndexFromVersion (DataRowVersion.Default);
childCols [i].DataContainer.CopyValue(parentCols [i].DataContainer, defaultIdx, Proposed);
}
}
}
#endif // NET_2_0
+
+ DataColumn GetColumn (string columnName)
+ {
+ DataColumn column = _table.Columns [columnName];
+
+ if (column == null)
+ throw new ArgumentException ("The column '" + columnName + "' does not belong to the table " + _table.TableName);
+
+ return column;
+ }
}
}