views:

652

answers:

2

Hi,

At work we use typed dataset in some projects for our DataAccess layer. Sometimes we extend them using the partial class feature : using View code on a dataset create a DataSetName.cs with the partial class declaration where you can add code. Inside this file we also add the TableAdapter partial class.

Recently we migrated on Visual Studio 2008 from VS 2005. The behavior of the dataset generator seems to be different in VS 2008. It removed a part in the TableAdapter namespace in the .cs file :

Example :

Original code :


namespace ClassLibrary1.Dataset.DataSet1TableAdapters  
{  
   public partial class CategoriesTableAdapter  
   {  
   }  
}

After migration in VS 2008 :


namespace ClassLibrary1.DataSet1TableAdapters  
{  
   public partial class CategoriesTableAdapter  
   {  
   }  
}

The namespace changed ! It has been replaced by the root namespace of the project.

Reproduction steps :

  1. Create a class library project.
  2. Add a folder called Dataset or whatever in the project.
  3. Add a dataset inside the folder (DataSet1).
  4. Drop a table in the dataset designer (I used a table from Northwind).
  5. Right click on the dataset in the Solution Explorer and choose View Code. It will create a DataSet1.cs file with a partial class of the dataset inside.
  6. Copy the namespace and class for the table adapter from DataSet1.Designer.cs and paste it inside DataSet1.cs.
  7. Run custom tool on the dataset, it works !
  8. Close solution
  9. Open the solution again
  10. Run custom tool on the dataset, namespace modified for the tableAdapter, very annoying :(

My Machine : Windows Server 2003 R2 Standard Edition SP2 Visual Studio 2008 Pro (9.0.21022.8 RTM) Also tested on a colleague's computer running XP.

Anyone already experiencied the same weird behavior ? Did I made something wrong ? Is there something new to configure inside Visual Studio 2008 to make it works like it did in VS 2005 ?

+1  A: 

Having a namespace that is also a class name causes confusion. Microsoft apparently decided to fix a namespace generation bug in this case. I would recommend fixing your namespaces rather than trying to find some workaround to have it the old way.

Joe Caffeine
What do you mean about fixing my namespaces ? I don't have any namespace that match an existing class name :( But thanks you for your for the tips, it's always something that good to know !
Cédric V
A: 

Visual Studio 2008 SP1 fixed this issue.

Cédric V