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
- Go to Windows Explorer and delete both the dbml and designer.cs files
- Go to Visual Studio and hit Refresh in the Solution Explorer. The dbml and designer.cs files now disappear from the project.
- Regenerate the dbml file using SqlMetal
- 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?