views:

6713

answers:

6

I'm using LINQ to SQL classes in a project where the database design is still in a bit of flux.

Is there an easy way of synchronising the classes with the schema, or do I need to manually update the classes if a table design changes?

+4  A: 

I think Jeff complained about this recently. One common technique is to drag all the objects into the designer again...

I hope someone else chimes in with a better approach!

Michael Haren
This is what we're doing...and it's starting to get very annoying! :-)
Richard Ev
+36  A: 

You can use SQLMetal.exe to generate your dbml and or cs/vb file. Use a pre-build script to start it and target the directory where your datacontext project belongs.

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\x64\sqlmetal.exe 
  /server:<SERVER> 
  /database:<database> 
  /code:"path\Solution\DataContextProject\dbContext.cs" 
  /language:csharp 
  /namespace:<your namespace>
vzczc
This is great! I figured I just had to redrag everything into the dbml.
naspinski
unfortunately there is no option to filter only the desired tables/sprocs/schemas...
Seiti
A: 

The best way is to re sync the designer. Since it is automatically generated code it should not be too much work.

If you are writing the classes yourself then you are stuck doing the updates.

David Basarab
What do you mean "re sync the designer" ? I cannot find such a feature in Visual Studio 2008? It seems pretty well documented that there is no feature in VS to update a table in the dbml by re-scanning the database server schema for that table." Please clarify what you are telling us?
MattSlay
+13  A: 
Espo
FYI -- there is a free 30 trial available at that site, and a single user license fee of just over $100.
Dan Esparza
I've tried it. Seems to work as expected - doesn't interfere with existing relationships, etc (which saves a big pain in the butt of having to rename tables, re-establish serialization properties on relationships, etc.) Thanks for the link!
Dan Esparza
Works great !
Svish
Really great stuff!
Stuck
+3  A: 

DamienG has written some t4 templates which can replace some of what VS generates for you. These can be rerun whenever you like via a command line tool.

T4 templates have the added benefit of being editable. This allows you to tweak what is generated to you hearts content.

Rory Becker
+1  A: 

I wrote a tool to do script changes to Dbml scripts see http://code.google.com/p/linqtodbmlrunner/ and my blog http://www.adverseconditionals.com

mcintyre321