keep LinqToSQL sync with the database

百般思念 提交于 2019-12-22 18:56:15

问题


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.


回答1:


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:
    • http://www.huagati.com/dbmltools/
    • http://www.perpetuumsoft.com/Product.aspx?lang=en&pid=55&tid=linqtosqlsynchronization



回答2:


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




回答3:


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.

  • http://csainty.blogspot.com/2008/02/linq-to-sql-sqlmetalexe.html
  • http://blog.benhall.me.uk/2007/08/power-of-sqlmetal.html

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



来源:https://stackoverflow.com/questions/914606/keep-linqtosql-sync-with-the-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!