2.18. Controlling the Names Used in a Strongly Typed DataSet
Problem
You want to assign your own
names
to the classes and properties for strongly typed
DataSet classes.
Solution
Use annotations in the XML schema to control the names of classes and
properties in strongly typed DataSet classes.
The sample uses one XSD file:
CategoriesDS_AnnotatedName.xsdThe schema used to generate the strongly typed
DataSet. The schema is annotated so that you can access the collection of rows in the table by using theCategorysproperty of theDataSetrather than categories, each row by using theCategoryproperty of the row collection rather thanCategoriesRow, and theCategoryNamefield by using theNameproperty of the row rather thanCategoryName. The annotations are marked in bold in the Example 2-23.
Example 2-23. File: TypedDataSets\CategoriesDS_AnnotatedName.xsd
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="CategoriesDS_AnnotatedName"
targetNamespace=
"http://www.tempuri.org/CategoriesDS_AnnotatedName.xsd"
xmlns:mstns="http://www.tempuri.org/CategoriesDS_AnnotatedName.xsd"
xmlns="http://www.tempuri.org/CategoriesDS_AnnotatedName.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="CategoriesDS_AnnotatedName" msdata:IsDataSet="true"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="Categories" ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access