views:

2572

answers:

1

I am using SqlMetal to general my DataContext.dbml class for my ASP.net application using LinqToSql. When I initially created the DataContext.dbml file, Visual Studio used this to create a related DataContext.designer.cs file. This designer file contains the DataContext class in C# that is used throughout the app (and is derived from the XML in the dbml file) and is essential to bridging the gap between the output of SqlMetal and using the DataContext with LinqToSql.

However, when I make a change to the database and recreate the dbml file, the designer file never gets regenerated in my website. Instead, the old designer file is maintained (and therefore none of the changes to the DBML file are accessible through the LinqToSql DataContext class).

The only process I have been able to use so far to regenerate the designer file is

  1. Go to Windows Explorer and delete both the dbml and designer.cs files
  2. Go to Visual Studio and hit Refresh in the Solution Explorer. The dbml and designer.cs files now disappear from the project.
  3. Regenerate the dbml file using SqlMetal
  4. Go to Visual Studio and hit Refresh in the Solution Explorer. Now the designer.cs file is recreated.

It seems that Visual Studio will only generate the designer.cs file when a new dbml file is detected that does not yet have a designer.cs file. This process is pretty impractical, since it involves several manual steps and messes things up with source control.

Does anyone know how I can get the designer.cs file automatically regenerated without having to follow the manual delete/refresh/regenerate/delete process outlined above?

+2  A: 

The designer.cs file is normally maintained automatically as you make changes to the DBML within Visual Studio. If VS isn't running when you recreate the DBML it may not know.

Check that the .DBML file in Visual Studio has Custom Tool property set to MSLinqToSQLGenerator. If it isn't, then set it to that. If it is try right-clicking on the DBML after making changes and choosing Run Custom Tool to see if that updates the .designer.cs.

Original Poster: Run Custom Tool worked inside Visual Studio to regenerate the designer.cs file.

I also found a better solution - you can generate the class file using SqlMetal: "sqlmetal /code:DataContext.designer.cs /language:csharp DataContext.dbml".

DamienG