我如何更新一个Linq到SQL .dbml文件?
当前回答
要更新你的.dbml-diagram中的表,例如,添加列,这样做:
更新SQL Server资源管理器窗口。 将表的“新”版本拖到.dbml-diagram(下图中的report1)中。
在新版本的表中标记添加的列,按Ctrl+C复制添加的列。
单击表的“旧”版本,并按Ctrl+V将添加的列粘贴到已经存在的表版本中。
从步骤2中删除拖拽的表并保存.dbml文件。
其他回答
在存储过程更新的情况下,应该从.dbml文件中删除它,然后重新插入它。但是如果存储过程有两条路径(例如:if something;显示一些列;否则显示一些其他列),确保两个路径有相同的列别名!!否则只有第一个路径列存在。
We use a custom written T4 template that dynamically queries the information_schema model for each table in all of our .DBML files, and then overwrites parts of the .DBML file with fresh schema info from the database. I highly recommend implementing a solution like this - it has saved me oodles of time, and unlike deleting and re-adding your tables to your model you get to keep your associations. With this solution, you'll get compile-time errors when your schema changes. You want to make sure that you're using a version control system though, because diffing is really handy. This is a great solution that works well if you're developing with a DB schema first approach. Of course, I can't share my company's code so you're on your own for writing this yourself. But if you know some Linq-to-XML and can go to school on this project, you can get to where you want to be.
使用Visual Studio 2019在图形设计器中打开DBML文件更新DBML文件。
不工作时:https://developercommunity.visualstudio.com/t/dbml-files-not-opening-in-graphic-designer-in-vs-2/1659675
只是为了记录
要更新你的.dbml-diagram中的表,例如,添加列,这样做:
更新SQL Server资源管理器窗口。 将表的“新”版本拖到.dbml-diagram(下图中的report1)中。
在新版本的表中标记添加的列,按Ctrl+C复制添加的列。
单击表的“旧”版本,并按Ctrl+V将添加的列粘贴到已经存在的表版本中。
从步骤2中删除拖拽的表并保存.dbml文件。
我建议使用VS2008内置的可视化设计器,因为更新dbml也会更新为您生成的代码。在可视化设计器之外修改dbml将导致底层代码不同步。