K
Ken Allen
I am having some difficulties with determining how to leverage the use of
typed datasets with a specific schema. The problem lies with the definition
of a 'relationship', at least when defining the typed dataset via the IDE.
The IDE forces me to define a relationship from a parent to a child,
requiring the parent to be the one with the Primary Key and the child to
contain a column of the same type (not necessarily part of its primary key).
This works fine in many cases, such as Customer --> Orders, where the
Customer record is the parent and the Orders record contains a (possibly
non-primary key) column that contains the CustomerID.
In other cases this is not the actual case: consider the somewhat artificial
situation where we shall classify disk drives into 'levels' based on a
capacity range. So the [Levels] table will contain a primary key of LevelID
and the remainder of the fields will describe each specific level. The
[Drives] table will contain a primary key of DriveID and will also contain a
non-key field named LevelID; in the database there shall be a foreign key
defined between these tables based on the LevelID column. In the typed
dataset, I am forced to define the relationship with [Levels] as the parent,
but in fact the levels are merely a lookup mechanism to permit normalization
of the data. When I display the [Drives] entries, I want to show some
columns from the [Levels] table, either in addition to or in place of the
LevelID column value itself, but I do not wish to treat the [Drives] as
children of the [Levels], since [Levels] are not control objects, merely
lookup information.
I am likely missing something here, but since all of the source material I
have found, in books and online, refers to the Customer/Order paradigm and
not to the Drives/Levels scenario, I am uncertain how I can leverage the use
of typed datasets to avoid the use of a JOIN to retrieve the information
that I want.
Also, I can find no way to define calculated columns as part of a typed
dataset, at least from within the IDE. Is this possible? In the classic
Customer/Orders paadigm, I would want to define a calculated column in the
typed data table [Customers] to contain the number of [Orders] that are
'open' as well as the total value of those orders, but I can find no way to
define such a calculated column unless I place it in the database, which I
do not want. I have come across numerous examples of doing this with
programmatically created untyped datasets, but I can find no reference on
how to do this with a typed dataset, and expecially from within the IDE.
Finally, I am concerned with the amount of work that one must do to update a
typed dataset to reflect changes made to the actual schema. From an earlier
post it was pointed out that business rules should be added to a further
sub-class of the typed dataset, such that most changes to the typed dataset
would not invalidate the derived class (but would require that it be
recompiled), except where columns or relations were renamed or removed;
obviously new code has to be added to deal with new columns and
relationships. But is there no alternative aside from forcing one to
re-generate the XSD from scratch again, with all the manual steps to define
the relationships and calculated columns (if this can be done)?
-ken
typed datasets with a specific schema. The problem lies with the definition
of a 'relationship', at least when defining the typed dataset via the IDE.
The IDE forces me to define a relationship from a parent to a child,
requiring the parent to be the one with the Primary Key and the child to
contain a column of the same type (not necessarily part of its primary key).
This works fine in many cases, such as Customer --> Orders, where the
Customer record is the parent and the Orders record contains a (possibly
non-primary key) column that contains the CustomerID.
In other cases this is not the actual case: consider the somewhat artificial
situation where we shall classify disk drives into 'levels' based on a
capacity range. So the [Levels] table will contain a primary key of LevelID
and the remainder of the fields will describe each specific level. The
[Drives] table will contain a primary key of DriveID and will also contain a
non-key field named LevelID; in the database there shall be a foreign key
defined between these tables based on the LevelID column. In the typed
dataset, I am forced to define the relationship with [Levels] as the parent,
but in fact the levels are merely a lookup mechanism to permit normalization
of the data. When I display the [Drives] entries, I want to show some
columns from the [Levels] table, either in addition to or in place of the
LevelID column value itself, but I do not wish to treat the [Drives] as
children of the [Levels], since [Levels] are not control objects, merely
lookup information.
I am likely missing something here, but since all of the source material I
have found, in books and online, refers to the Customer/Order paradigm and
not to the Drives/Levels scenario, I am uncertain how I can leverage the use
of typed datasets to avoid the use of a JOIN to retrieve the information
that I want.
Also, I can find no way to define calculated columns as part of a typed
dataset, at least from within the IDE. Is this possible? In the classic
Customer/Orders paadigm, I would want to define a calculated column in the
typed data table [Customers] to contain the number of [Orders] that are
'open' as well as the total value of those orders, but I can find no way to
define such a calculated column unless I place it in the database, which I
do not want. I have come across numerous examples of doing this with
programmatically created untyped datasets, but I can find no reference on
how to do this with a typed dataset, and expecially from within the IDE.
Finally, I am concerned with the amount of work that one must do to update a
typed dataset to reflect changes made to the actual schema. From an earlier
post it was pointed out that business rules should be added to a further
sub-class of the typed dataset, such that most changes to the typed dataset
would not invalidate the derived class (but would require that it be
recompiled), except where columns or relations were renamed or removed;
obviously new code has to be added to deal with new columns and
relationships. But is there no alternative aside from forcing one to
re-generate the XSD from scratch again, with all the manual steps to define
the relationships and calculated columns (if this can be done)?
-ken