2.17. 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.
Use the Visual Studio .NET IDE to create the strongly typed DataSet object based on the HumanResources.Department table in AdventureWorks that you will annotate. For more details about creating a strongly typed DataSet using the Visual Studio .NET IDE, see Recipe 2.16. Follow these steps:
Create a Visual C# Console Application named
AnnotateStronglyTypedDataSet.Right-click on the project in Solution Explorer and click Add → New Item to open the Add New Item dialog shown in the following figure. Select
DataSetfrom the Visual Studio installed templates. Name theDataSetAnnotatedDepartment.xsd. Click the Add button to create theDataSetand close the dialog. TheDataSetis added to Solution Explorer and the DataSet Designer is opened.Next, add database objects to the
DataSetusing a Database Connection. If you do not already have anAdventureWorksDatabase Connection, create one: Open Server Explorer by selecting View → Server Explorer from the main menu. Rightclick on the Data Connections node and select Add Connection from the context menu to Open the Add Connection dialog. In the Add Connection dialog, select the SQL Server with theAdventureWorksdatabase, leave log on mode as Windows Authentication, ...
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