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   

My Links

Ads Via DevMavens

Archives

Post Categories

 

I am a Microsoft MVP for ASP.NET.
I am an ASPInsider.
<January 2009>
SMTWTFS
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

Comment Stats

DayTotal% of Total
Sunday 1996.9%
Monday 41014.2%
Tuesday 48716.8%
Wednesday 53618.5%
Thursday 56119.4%
Friday 52118.0%
Saturday 1806.2%
Total 2894100.0%

Hour1Total% of Total
12:00 AM 712.5%
1:00 AM 782.7%
2:00 AM 652.2%
3:00 AM 782.7%
4:00 AM 622.1%
5:00 AM 1164.0%
6:00 AM 1123.9%
7:00 AM 1685.8%
8:00 AM 1826.3%
9:00 AM 1545.3%
10:00 AM 1816.3%
11:00 AM 1866.4%
12:00 PM 1966.8%
1:00 PM 1816.3%
2:00 PM 1655.7%
3:00 PM 1344.6%
4:00 PM 1133.9%
5:00 PM 1023.5%
6:00 PM 983.4%
7:00 PM 1043.6%
8:00 PM 893.1%
9:00 PM 832.9%
10:00 PM 852.9%
11:00 PM 913.1%
Total 2894100.0%

Comments by Blog Entry Date/Time

Day Entry MadeAvg.Total
Sunday 5.18145
Monday 5.01371
Tuesday 4.25463
Wednesday 7.54656
Thursday 6.71658
Friday 5.32431
Saturday 5.00170
Total 5.662894

Hour1 Entry MadeAvg.Total
12:00 AM 5.2937
1:00 AM 1.002
5:00 AM 0.000
7:00 AM 6.3338
8:00 AM 4.52122
9:00 AM 6.04284
10:00 AM 6.14264
11:00 AM 4.30189
12:00 PM 6.75344
1:00 PM 3.12128
2:00 PM 5.23225
3:00 PM 8.36301
4:00 PM 3.7694
5:00 PM 5.89165
6:00 PM 4.56114
7:00 PM 9.15183
8:00 PM 8.53162
9:00 PM 5.00115
10:00 PM 6.3395
11:00 PM 4.5732
Total 5.662894

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


Blog Stats

Favorite Web Sites

My Books

My MSDN Articles