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: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.


Specifies the display caption for the column. Maps to DataColumn.Caption.


Sets the expression used to filter rows, calculate the values in a column, or create an aggregate column. Maps to DataColumn.Expression.


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




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.


If set to true, the indicated field is identified as a primary key for the table.

Table B-6. msdata keyref attributes




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.


Maps to ForeignKeyConstraint.ConstraintName. If it is not specified, name attribute of the keyref element is used instead.


Maps to ForeignKeyConstraint.UpdateRule. If it is not specified, Cascade is used by default.


Maps to ForeignKeyConstraint.DeleteRule. If it is not specified, Cascade is used by default.


Maps to ForeignKeyConstraint.AcceptRejectRule. If it is not specified, None is used by default.


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:childkey="ChildColumnElement" />

Table B-7. msdata:Relationship attributes




The name of the complex type element that represents the parent row


The name of the complex type element that represents the child row


The name of the element that represents the parent column


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




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.


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.

    Part I: ADO.NET Tutorial
    Part II: ADO.NET Core Classes
    Part III: API Quick Reference