keep LinqToSQL sync with the database

2019-05-23 08:31发布

I am going to develop a new website with asp.net 3.5 and LinqToSQL. For maintainability purposes, how can I modify a Linq class if an attribute is added to a table in the database ?

Thank you.

3条回答
Ridiculous、
2楼-- · 2019-05-23 09:17

If you don't need to customize the Data model, or you can get away with simply customizing it through partial classes, then you can use SQLMetal.exe to generate your data model. It comes with .NET 3.5, and several people have written articles online about making batch files which you can run to automate the process.

Then, if you update your database, you just simply run the batch file and everything is synchronized again!

查看更多
唯我独甜
3楼-- · 2019-05-23 09:30

Unfortunately LinqToSQL does not have synchronization support in Visual Studio. The options are:

  1. Remove the table and add it again. Of course any customization changes are lost
  2. Edit the .dbml file file directly and add the attribute. The file has xml content and when saving it will regenerate the .cs file.
  3. Use 3'rd party addins like:
查看更多
Luminary・发光体
4楼-- · 2019-05-23 09:34

You will need to regenerate the model each time you changes to the underlying database.

查看更多
登录 后发表回答