B.2 msdata Namespace
The msdata
namespace extends a XSD document so that it can represent an ADO.NET
DataSet. The msdata namespace
is also used in XML documents: namely in the
DiffGram representation of a
DataSet (along with the diffgr
namespace). Here's an example of how the
msdata namespace is imported in an
XSD file:
<xs:schema id="DataSetName" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" >
One place where you'll see the
msdata namespace is in the element tag containing
the XSD structure. Here, an IsDataSet attribute
indicates that the schema is used to represent an ADO.NET
DataSet:
<xs:element name="DataSetName" msdata:IsDataSet="true" >
The element tag also supports optional
CaseSensitive and Local
attributes:
<xs:element name="DataSetName"
msdata:CaseSensitive="true" msdata:Locale="en">
More importantly, the msdata namespace represents
various DataColumn properties that
don't have direct XSD mappings. Table B-4 lists these.
Table B-4. msdata column attributes
AutoIncrement,
AutoIncrementSeed,
AutoIncrementStep
|
Sets the auto-incrementing options for unique identity fields. These
attributes map to corresponding DataColumn
properties.
|
Caption
|
Specifies the display caption for the column. Maps to
DataColumn.Caption.
|
Expression
|
Sets the expression used to filter rows, calculate the values in a
column, or create an aggregate column. Maps to
DataColumn.Expression.
|
ReadOnly
|
Indicates (true or false)
whether the value can be changed. This maps to
DataColumn.ReadOnly.
|
The msdata namespace is also used with
unique elements (to specify a unique constraint
for a field), key elements (to specify the primary
key for a table), and keyref elements (to specify
relations between two tables). These elements are introduced in Chapter 4. See Table B-5 and Table B-6.
Table B-5. msdata unique and key attributes
ConstraintName
|
If this attribute is specified, its value is used as the constraint
name in the DataSet.Contraints collection.
Otherwise, the name attribute provides the constraint name.
|
PrimaryKey
|
If set to true, the indicated field is identified
as a primary key for the table.
|
Table B-6. msdata keyref attributes
ConstraintOnly
|
When set to true, a constraint is created on the
DataSet but no relation is created. If this
attribute isn't specified (or is set to
false), both the constraint and the relation are
created.
|
ConstraintName
|
Maps to ForeignKeyConstraint.ConstraintName. If it
is not specified, name attribute of the
keyref element is used instead.
|
UpdateRule
|
Maps to ForeignKeyConstraint.UpdateRule. If it is
not specified, Cascade is used by default.
|
DeleteRule
|
Maps to ForeignKeyConstraint.DeleteRule. If it is
not specified, Cascade is used by default.
|
AcceptRejectRule
|
Maps to ForeignKeyConstraint.AcceptRejectRule. If
it is not specified, None is used by default.
|
IsNested
|
This is true if the relationship is nested
(meaning the elements of the child table are grouped under the
appropriate parent row in the XML file).
|
When you use a keyref element in a schema, there
will be one of two results:
If the ConstraintOnly attribute is
false, a ForeignKeyConstraint
and a DataRelation object are created and added to
the DataSet.
If the ConstraintOnly attribute is
true, a ForeignKeyConstraint
object is created an added to the DataSet, but a
DataRelation isn't.
If you want to create a
DataRelation without a
ForeignKeyConstraint, you need to add an entirely
new element to the schema document:
msdata:Relationship. This element is shown below
and in Table B-7.
<msdata:Relationship name="RelationshipName"
msdata:parent="ParentElement"
msdata:child="ChildElement"
msdata:parentkey="ParentColumnElement"
msdata:childkey="ChildColumnElement" />
Table B-7. msdata:Relationship attributes
parent
|
The name of the complex type element that represents the parent row
|
child
|
The name of the complex type element that represents the child row
|
parentkey
|
The name of the element that represents the parent column
|
childkey
|
The name of the element that represents the child column
|
Finally, the msdata namespace is used with the
DiffGram if you want to set a
specific column order or hide a row. There are two valid
msdata attributes that you can apply to row
elements in a DiffGram, and they are described in Table B-8.
Table B-8. msdata DiffGram row attributes
rowOrder
|
A zero-based index number that can specify a column ordering other
than the one in which the columns are listed in the DiffGram. For
example, the row with rowOrder="0" automatically
becomes the first column in the DataSet.
|
hidden
|
This attribute is used if the
DataColumn.ColumnMapping property for a column is
set to MappingType.Hidden. In this case, the
column value is written in the DiffGram as a special hidden
attribute, using the syntax
msdata:hiddenColumnName="value".
An example might be
msdata:hiddenContactTitle="Owner". If a hidden
column is empty, its value isn't written to the
DiffGram.
|
|