We got the same behavior while working on a project using ADO.NET 1.1. I don't
know if it is fixed in .NET 2.0 or if it will stay the same "by design". We got
around using the hack below. We tried several alternatives and it seems that
only this one is bulletproof.
public static void RefreshExpressionColumns(DataRow row, bool cascade) {
if (row == null)
throw new ArgumentNullException("row");
if (!cascade)
RefreshExpressionColumns(DataRow row);
else
{
int count = row.Table.ParentRelations.Count;
for (int i = 0; i < count; i++)
{
DataRow[] parents =
row.GetParentRows(row.Table.ParentRelations[i]);
for (int j = 0; j < parents.Length; j++)
{
DataRow parent = parents[j];
RefreshExpressionColumns(parent);
RefreshExpressionColumns(parent, true);
}
}
}
}
public static void RefreshExpressionColumns(DataRow row) {
if (row == null)
throw new ArgumentNullException("row");
switch (row.RowState)
{
case DataRowState.Unchanged:
row.BeginEdit();
row.EndEdit();
row.AcceptChanges();
break;
case DataRowState.Modified, DataRowState.Added:
row.BeginEdit();
row.EndEdit();
break;
}
}
S�bastien
-----Original Message-----
From: Chris Howlett [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 31, 2005 9:46 PM
Subject: ADO.NET Expression Columns - Aggregates of Aggregates
Say you have an expression column which is an aggregate of child columns which
are in turn aggregates of child columns. It appears to me that when you modify
the lowest level values, the aggregates are recomputed one level up, but not
two levels up. Is this the expected behaviour? I haven't been able to find
anything on it in the docs, this list's archives, or google.
A specific example, in case the above isn't clear. A dataset with three tables
- companies, offices, employees. office rows are children of company rows,
employees are children of office rows. employees have a sales column, a number.
Offices have a sales column, an expression column which is the sum of the child
employees sales. Companies have a sales column, an expression column which is
the sum of the child office sales.
Create an empty such dataset. Add a company, an office for the company and an
employee for the office. Set the employee sales to 5.
Then the office sales will be 5, but the company sales will be null. In
general, the office sales respond to changes in employee sales as you'd expect,
but company sales do not. If you reassign the expression value for company
sales to itself at any point, it will recompute correctly. Interesting but not
really helpful.
This is 1.1, I haven't tried 2.0.
Can anyone offer any insight or pointers to any place where this is discussed?
Thanks,
Chris
===================================
This list is hosted by DevelopMentor� http://www.develop.com
<http://www.develop.com>
View archives and manage your subscription(s) at http://discuss.develop.com
<http://discuss.develop.com>
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com