The Namespace and Class Names for Strongly Typed DataSets and TableAdapters

Published 22 June 06 07:34 AM | Scott Mitchell

In my multi-part tutorial series on Working with Data in ASP.NET 2.0, the tutorials are built upon an application architecture that uses a Typed DataSet as the Data Access Layer (DAL) and custom classes for the Business Logic Layer (BLL). In the first tutorial, the DAL is created, resulting in the following business objects:

  • Northwind - the strongly-typed DataSet that has the set of strongly-typed DataTables and the relationships among them
  • Northwind.ProductsDataTable - a strongly-typed DataTable that provides information about a set of products
  • Northwind.ProductsRow - a strongly-typed DataRow that provides information about a particular product instance; has properties like ProductID, ProductName, UnitPrice, and so on.

There are other business object classes that model the other tables in the database - Northwind.CategoriesDataTable, Northwind.CategoriesRow, and so on.

In addition to these business objects, the Typed DataSet includes TableAdapters, which provide the methods for populating these business objects with data from the database (as well as methods for inserting, updating, and deleting data). The TableAdapter classes automatically created by the Typed DataSet include one for each DataTable, and are found in the NorthwindTableAdapters namespace. These classes include:

  • ProductsTableAdapter
  • CategoriesTableAdapter
  • SuppliersTableAdapter
  • EmployeesTableAdapter

A question I've received from a number of folks who've read the tutorials is, “How do I change the names of these classes?” The names for the Typed DataSet, its DataTables and DataRows, and the TableAdpaters and their namespace are all determined by properties for these objects. By default, the name for the DataSet is the name of the DataSet file in your project. For the tutorial, I named the DataSet file Northwind.xsd, hence the Typed DataSet name is Northwind.

If you don't want to use the name of the DataSet file as the Typed DataSet name, you can change it by opening the DataSet in the Designer view, going to the Properties window, and changing the Name setting from Northwind (or whatever) to the name you desire. Imagine that you wanted to change the name to Scott, in an attempt to pump up my already overinflated ego. After doing so (and saving the DataSet file), the class names would change to:

  • Scott
  • Scott.ProductsDataTable
  • Scott.ProductsRow
  • ...

And the TableAdapters would all be in the ScottTableAdapters namespace. Similarly, to change the name of a DataTable or TableAdapter, click on the DataTable or TableAdapter in the DataSet Designer, go to the Properties window, and change the Name property. That's all there is to it!

Happy Programming!

Filed under:

Comments

# Bazzer Cunn said on July 3, 2010 05:31 PM:

I am trying a tutorial an dI have added the Northwind DB as a datasource and ProductsTableAdapter but in .cs it does not like the line  'using NorthwindTableAdapters' I have not found a good explanation yet of exactly ths reference line - Like is it there am adpaters  namespace created by default when you add Data souce to project and it will always be of the format <databasename>TableAdpaters - When Visual Studio is saying that the namespace is missing whattypes of things should one check?

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.