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
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?
DBML (Database Markup Language) is an open-source DSL language designed to define and document database schemas and structures. It is designed to be simple, consistent and highly-readable. It also comes with command-line tool and open-source module to help you convert between DBML and SQL.
Choose Add New Item, then under Data, choose Linq-To-SQL Classes . This will create an empty DBML file. You'll then need to create a server connection to a database and drag the tables you want into the DBML designer. Once you save, Visual Studio will regenerate the DBML with entities for your chosen tables.
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.
You can also generate the class file using SqlMetal:
sqlmetal /code:DataContext.designer.cs /language:csharp DataContext.dbml
Not sure how It did it, but here are some things I worked on to get it back.
Something had it locked, so it generated a new db.designer.cs file (db1.designer.cs).
I had beyond compare open, comparing that file to the previous one (BC isn't supposed to lock and I don't think it was the problem, never had that problem before with it.)
Open the project file in notepad and look for these entries, i revereted to the previous version in source control..
this is what i brought back.
<Compile Include="db.designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>db.dbml</DependentUpon>
</Compile>
...
<LastGenOutput>db.designer.cs</LastGenOutput>
the lastgenOutput was set to db1.desginer.cs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With