C# – Best way to update LINQ to SQL classes after database schema change

clinq-to-sqlnet

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?

Best Answer

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>