DekGenius.com
[ Team LiB ] Previous Section Next Section

B.1 codegen Namespace

The codegen namespace gives you fine-grained control of a typed DataSet. By adding codegen attributes, you can configure the names that are used for methods, properties, relations, and constraints. When using the codegen namespace, it should be imported as shown:

<xs:schema id="DataSetName" xmlns="" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
    xmlns:codegen="urn:schemas-microsoft-com:xml-msprop" >

codegen attributes configure the names used in strongly typed DataSet objects. They do not have any effect on the functionality of the generated DataSet class.

Table B-1 indicates where the various codegen attributes can be used and what they accomplish. Table B-2 briefly describes each attribute.

Table B-1. codegen attribute use

Typed DataSet object/method/event

Default name

codegen attribute

DataTable
TableNameDataTable
typedPlural
DataTable Methods
NewTableNameRow 
AddTableNameRow
DeleteTableNameRow
typedName
DataRowCollection
TableName
typedPlural
DataRow
TableNameRow
typedName
DataColumn
DataTable.ColumnNameColumn
DataRow.ColumnName
typedName
Property
PropertyName
typedName
Child Accessor
GetChildTableNameRows
typedChildren
Parent Accessor
TableNameRow
typedParent
DataSet Events
TableNameRowChangeEvent 
TableNameRowChangeEventHandler
typedName

Table B-2. codegen atttributes

Attribute

Description

typedName

Name of the object in the generated class.

typedPlural

The name of the object in a collection of objects. For example, if you specify Category for typedName and Categories for typedPlural, you generate a Categories collection and a Category row (instead of a CategoriesRow).

typedParent

Name of the object when referred to in a parent relationship. Typed datasets automatically generate methods that provide access to parent and child rows. For example, if you specify Category for the typedParent of an order record, use a Order.Category( ) method instead of Order.GetCategoriesRow( ).

typedChildren

Name of the method to return objects from a child relationship. For example, if you specify Order for the typedChild of a category record, use a Category.Orders( ) method instead of Category.GetOrdersRows( ).

nullValue

Indicates the behavior when null values are encountered. See Table B-3 for possible values.

Finally, Table B-3 identifies possible values for the nullValue attribute.

Table B-3. Values for nullValue

Value

Description

[Replacement Value]

Specifies a value to be returned. For example, use nullValue="0" to set null integer fields to 0.

_throw

Throws an exception when a null value is encountered. This is the default.

_null

Returns a null reference (or throws an exception if a primitive type is encountered).

_empty

For strings, returns String.Empty. For objects, returns the default uninitialized object (created from the zero-parameter constructor). If a primitive type is encountered, ADO.NET generates an exception.

    [ Team LiB ] Previous Section Next Section