Scott on Writing

Musings on technical writing...

The Namespace and Class Names for Strongly Typed DataSets and TableAdapters

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!

posted on Thursday, June 22, 2006 7:34 AM

Feedback

# re: The Namespace and Class Names for Strongly Typed DataSets and TableAdapters 6/23/2006 12:56 PM Michael

Do you know if there is a way to rename the "DataTable" and "Row" text that is appended to the class? For example, we would like to call it "ProductCollection" and "ProductEntity" rather than "ProductDataTable" and "ProductRow"?

# re: The Namespace and Class Names for Strongly Typed DataSets and TableAdapters 6/23/2006 10:49 PM Kamran Shahid

Yah I also Want's to ask the same question.
Also Could You also doing something for transaction handling in the tutorial series

# re: The Namespace and Class Names for Strongly Typed DataSets and TableAdapters 7/6/2006 3:45 PM Jamie

Seriously... Inquiring minds want to know! Also, is there any way to see the code that gets generated in C# or is it put directly into IL?

# re: The Namespace and Class Names for Strongly Typed DataSets and TableAdapters 8/8/2006 10:42 PM CWChan

Do you know of any way to set the namespace of an asp.net 2.0 website? Or the namespace of the typed dataset within the website project?

# re: The Namespace and Class Names for Strongly Typed DataSets and TableAdapters 8/25/2006 8:39 AM Anton Backer

Jamie: It generates C#, and not IL, so you can actually see it if you put a breakpoint in your code and step into it. Don't bother modifying that code, however, because next time you update the dataset the modifications will be wiped as the code is re-generated. If you want to modify the code, make use of the fact that it's a partial class.

CWChan: to set the namespace of a typed dataset, change the filename of the dataset to Namespace.Name.xsd. To set the namespace of a whole project, go to project properties -> application, although i'm not sure if you can set the namespace of a web project the same way.

# re: The Namespace and Class Names for Strongly Typed DataSets and TableAdapters 10/10/2006 2:26 PM BC

Any idea how to do this in VB? I noticed you were using C#. I am using VB and VS2005, but it still does not work for me.

-BC

Title:  
Name:  
Url:
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments   

Add To Your Reader

My Links

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<May 2008>
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1866.8%
Monday 37913.9%
Tuesday 45316.7%
Wednesday 50418.5%
Thursday 53519.7%
Friday 49418.2%
Saturday 1666.1%
Total 2717100.0%

Hour1Total% of Total
12:00 AM 652.4%
1:00 AM 682.5%
2:00 AM 622.3%
3:00 AM 742.7%
4:00 AM 572.1%
5:00 AM 1033.8%
6:00 AM 1084.0%
7:00 AM 1585.8%
8:00 AM 1716.3%
9:00 AM 1475.4%
10:00 AM 1716.3%
11:00 AM 1816.7%
12:00 PM 1886.9%
1:00 PM 1696.2%
2:00 PM 1605.9%
3:00 PM 1324.9%
4:00 PM 1073.9%
5:00 PM 923.4%
6:00 PM 913.3%
7:00 PM 963.5%
8:00 PM 833.1%
9:00 PM 782.9%
10:00 PM 792.9%
11:00 PM 772.8%
Total 2717100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.54144
Monday 5.22339
Tuesday 4.28419
Wednesday 7.67637
Thursday 6.90607
Friday 5.48411
Saturday 5.33160
Total 5.842717

Hour1 Entry MadeAvg.Total
12:00 AM 5.0035
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 7.0035
8:00 AM 5.35107
9:00 AM 6.32278
10:00 AM 6.47246
11:00 AM 4.41181
12:00 PM 6.88330
1:00 PM 3.00111
2:00 PM 5.41222
3:00 PM 8.64285
4:00 PM 4.0589
5:00 PM 5.92154
6:00 PM 4.52113
7:00 PM 9.67174
8:00 PM 9.80147
9:00 PM 5.05111
10:00 PM 5.4265
11:00 PM 4.5732
Total 5.842717

Learn More About Comment Stats
1 - All times GMT -8...


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles