Created
December 18, 2013 06:07
-
-
Save FrankFan/8017955 to your computer and use it in GitHub Desktop.
DataTable.Merge的内部实现
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal void MergeTable(DataTable src) | |
{ | |
bool enforceConstraints = false; | |
if (!this.isStandAlonetable) | |
{ | |
if (src.DataSet == this.dataSet) | |
{ | |
return; | |
} | |
enforceConstraints = this.dataSet.EnforceConstraints; | |
this.dataSet.EnforceConstraints = false; | |
} | |
else | |
{ | |
if (src == this.dataTable) | |
{ | |
return; | |
} | |
this.dataTable.SuspendEnforceConstraints = true; | |
} | |
if (this.dataSet != null) | |
{ | |
if ((src.DataSet == null) || (src.DataSet.namespaceURI != this.dataSet.namespaceURI)) | |
{ | |
this._IgnoreNSforTableLookup = true; | |
} | |
} | |
else if (((this.dataTable.DataSet == null) || (src.DataSet == null)) || (src.DataSet.namespaceURI != this.dataTable.DataSet.namespaceURI)) | |
{ | |
this._IgnoreNSforTableLookup = true; | |
} | |
this.MergeTableData(src); | |
DataTable dataTable = this.dataTable; | |
if ((dataTable == null) && (this.dataSet != null)) | |
{ | |
if (this._IgnoreNSforTableLookup) | |
{ | |
dataTable = this.dataSet.Tables[src.TableName]; | |
} | |
else | |
{ | |
dataTable = this.dataSet.Tables[src.TableName, src.Namespace]; | |
} | |
} | |
if (dataTable != null) | |
{ | |
dataTable.EvaluateExpressions(); | |
} | |
if (!this.isStandAlonetable) | |
{ | |
this.dataSet.EnforceConstraints = enforceConstraints; | |
} | |
else | |
{ | |
this.dataTable.SuspendEnforceConstraints = false; | |
try | |
{ | |
if (this.dataTable.EnforceConstraints) | |
{ | |
this.dataTable.EnableConstraints(); | |
} | |
} | |
catch (ConstraintException) | |
{ | |
if (this.dataTable.DataSet != null) | |
{ | |
this.dataTable.DataSet.EnforceConstraints = false; | |
} | |
throw; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment