Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to update LINQ to SQL classes after database schema change

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?

like image 671
Compile This Avatar asked Sep 02 '08 16:09

Compile This


People also ask

How do you update a record in LINQ?

You can update rows in a database by modifying member values of the objects associated with the LINQ to SQL Table<TEntity> collection and then submitting the changes to the database. LINQ to SQL translates your changes into the appropriate SQL UPDATE commands.

Is LINQ to SQL still used?

LINQ to SQL was the first object-relational mapping technology released by Microsoft. It works well in basic scenarios and continues to be supported in Visual Studio, but it's no longer under active development.


1 Answers

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> 
like image 93
vzczc Avatar answered Sep 22 '22 23:09

vzczc