ORM: 开发自己的Data Access Application Block - Part IIII
2008-12-06 10:15:37 来源:WEB开发网整个过程分3步骤,更新Deleted data.-> 更新Modified data.-> 更新Added data.真正的数据更新集中在UpdateDependentTable这样一个方法中。
private void UpdateDependentTable(DataTable table, DataRowState rowState)
{
DataViewRowState dataViewRowState = DataViewRowState.OriginalRows;
switch (rowState)
{
case DataRowState.Added:
{
dataViewRowState = DataViewRowState.Added;
break;
}
case DataRowState.Deleted:
{
dataViewRowState = DataViewRowState.Deleted;
break;
}
case DataRowState.Modified:
{
dataViewRowState = DataViewRowState.ModifiedCurrent;
break;
}
}
if (table.GetChanges(rowState) == null)
{
return;
}
DataTable parentTable = null;
DataTable childTable = null;
switch (rowState)
{
// DataRowState.Added|DataRowState.Modified: Parent table =>child table.
case DataRowState.Added:
case DataRowState.Modified:
{
foreach (DataRelation relation in table.ParentRelations)
{
parentTable = relation.ParentTable;
if (parentTable.GetChanges(rowState) == null)
{
continue;
}
this.UpdateDependentTable(parentTable, rowState);
}
DataRow[] updatedRows = table.Select(string.Empty, string.Empty, dataViewRowState);
this.UpdateIndependentTable(updatedRows);
foreach (DataRow row in updatedRows)
{
row.AcceptChanges();
}
foreach (DataRelation relation in table.ChildRelations)
{
childTable = relation.ChildTable;
if (childTable.GetChanges(rowState) == null)
{
continue;
}
this.UpdateDependentTable(childTable, rowState);
}
break;
}
// DataRowState.Deleted: Child table => Parent table.
case DataRowState.Deleted:
{
//Child Tables
foreach (DataRelation relation in table.ChildRelations)
{
childTable = relation.ChildTable;
if (childTable.GetChanges(rowState) == null)
{
continue;
}
this.UpdateDependentTable(childTable, rowState);
}
//Itself
DataRow[] updatedRows = table.Select(string.Empty, string.Empty, dataViewRowState);
this.UpdateIndependentTable(updatedRows);
foreach (DataRow row in updatedRows)
{
row.AcceptChanges();
}
//Parent Table.
foreach (DataRelation relation in table.ParentRelations)
{
parentTable = relation.ParentTable;
if (parentTable.GetChanges(rowState) == null)
{
continue;
}
this.UpdateDependentTable(parentTable, rowState);
}
}
break;
}
}
- ››开发Android 日历教程
- ››开发学院总结 Win 8实用技巧大全
- ››开发学院原创教程:把win8的IE10放桌面上方法(非...
- ››开发者眼中的Windows Phone和Android
- ››开发学院教你用SQL 语句最快速清空MySQL 数据表的...
- ››自己动手写iPhone wap浏览器之界面架构篇
- ››自己也能DIY个性真人QQ表情
- ››自己动手!巧法让酷狗动感歌词更完美
- ››自己编译Google Android内核的Linux源码
- ››自己写的一个jquery模板引擎(json比较好用)
- ››开发一个自己的HTML在线编辑器(一)
- ››开发一个自己的HTML在线编辑器(二)
更多精彩
赞助商链接