System.Data.DataTable.EvaluateExpressions C# (CSharp) Method

EvaluateExpressions() private method

private EvaluateExpressions ( DataRow row, DataRowAction action, List cachedRows ) : void
row DataRow
action DataRowAction
cachedRows List
return void
        internal void EvaluateExpressions(DataRow row, DataRowAction action, List<DataRow> cachedRows)
        {
            // evaluate all expressions for specified row
            if (action == DataRowAction.Add ||
                action == DataRowAction.Change ||
                (action == DataRowAction.Rollback && (row._oldRecord != -1 || row._newRecord != -1)))
            {
                // only evaluate original values if different from current.
                if (row._oldRecord != -1 && row._oldRecord != row._newRecord)
                {
                    EvaluateDependentExpressions(_dependentColumns, row, DataRowVersion.Original, cachedRows);
                }
                if (row._newRecord != -1)
                {
                    EvaluateDependentExpressions(_dependentColumns, row, DataRowVersion.Current, cachedRows);
                }
                if (row._tempRecord != -1)
                {
                    EvaluateDependentExpressions(_dependentColumns, row, DataRowVersion.Proposed, cachedRows);
                }
                return;
            }
            else if ((action == DataRowAction.Delete || (action == DataRowAction.Rollback && row._oldRecord == -1 && row._newRecord == -1)) && _dependentColumns != null)
            {
                foreach (DataColumn col in _dependentColumns)
                {
                    if (col.DataExpression != null && col.DataExpression.HasLocalAggregate() && col.Table == this)
                    {
                        for (int j = 0; j < Rows.Count; j++)
                        {
                            DataRow tableRow = Rows[j];

                            if (tableRow._oldRecord != -1 && tableRow._oldRecord != tableRow._newRecord)
                            {
                                EvaluateDependentExpressions(_dependentColumns, tableRow, DataRowVersion.Original, null);
                            }
                        }
                        for (int j = 0; j < Rows.Count; j++)
                        {
                            DataRow tableRow = Rows[j];

                            if (tableRow._tempRecord != -1)
                            {
                                EvaluateDependentExpressions(_dependentColumns, tableRow, DataRowVersion.Proposed, null);
                            }
                        }
                        // Order is important here - we need to update proposed before current
                        // Oherwise rows that are in edit state will get ListChanged/PropertyChanged event before default value is changed
                        // It is also the reason why we are not doping it in the single loop: EvaluateDependentExpression can update the
                        // whole table, if it happens, current for all but first row is updated before proposed value
                        for (int j = 0; j < Rows.Count; j++)
                        {
                            DataRow tableRow = Rows[j];

                            if (tableRow._newRecord != -1)
                            {
                                EvaluateDependentExpressions(_dependentColumns, tableRow, DataRowVersion.Current, null);
                            }
                        }
                        break;
                    }
                }

                if (cachedRows != null)
                {
                    foreach (DataRow relatedRow in cachedRows)
                    {
                        if (relatedRow._oldRecord != -1 && relatedRow._oldRecord != relatedRow._newRecord)
                        {
                            relatedRow.Table.EvaluateDependentExpressions(relatedRow.Table._dependentColumns, relatedRow, DataRowVersion.Original, null);
                        }
                        if (relatedRow._newRecord != -1)
                        {
                            relatedRow.Table.EvaluateDependentExpressions(relatedRow.Table._dependentColumns, relatedRow, DataRowVersion.Current, null);
                        }
                        if (relatedRow._tempRecord != -1)
                        {
                            relatedRow.Table.EvaluateDependentExpressions(relatedRow.Table._dependentColumns, relatedRow, DataRowVersion.Proposed, null);
                        }
                    }
                }
            }
        }

Same methods

DataTable::EvaluateExpressions ( ) : void
DataTable::EvaluateExpressions ( DataColumn column ) : void

Usage Example

        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;
                }
            }
        }
All Usage Examples Of System.Data.DataTable::EvaluateExpressions
DataTable