我如何更新一个Linq到SQL .dbml文件?
当前回答
下面是对我有效的完整的分步方法,用于更新LINQ to SQL dbml和相关文件,以包括我添加到一个数据库表中的新列。
您需要对您的设计表面进行上述其他建议的更改;但是,您需要执行一些额外的步骤。以下是完整的步骤:
Drag your updated table from Server Explorer onto the design surface Copy the new column from this "new" table to the "old" table (see M463 answer for details on this step) Delete the "new" table that you just dragged over Click and highlight the stored procedure, then delete it Drag the new stored procedure and drop into place. Delete the .designer.vb file in the code-behind of the .dbml (if you do not delete this, your code-behind containing the schema will not update even if you rebuild and the new table field will not be included) Clean and Rebuild the solution (this will rebuild the .designer.vb file to include all the new changes!).
其他回答
使用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文件。
下面是对我有效的完整的分步方法,用于更新LINQ to SQL dbml和相关文件,以包括我添加到一个数据库表中的新列。
您需要对您的设计表面进行上述其他建议的更改;但是,您需要执行一些额外的步骤。以下是完整的步骤:
Drag your updated table from Server Explorer onto the design surface Copy the new column from this "new" table to the "old" table (see M463 answer for details on this step) Delete the "new" table that you just dragged over Click and highlight the stored procedure, then delete it Drag the new stored procedure and drop into place. Delete the .designer.vb file in the code-behind of the .dbml (if you do not delete this, your code-behind containing the schema will not update even if you rebuild and the new table field will not be included) Clean and Rebuild the solution (this will rebuild the .designer.vb file to include all the new changes!).
我建议使用VS2008内置的可视化设计器,因为更新dbml也会更新为您生成的代码。在可视化设计器之外修改dbml将导致底层代码不同步。
更新表和更新DBML之间有细微差别…如果对现有表进行了更改,外键关系并不总是立即引入。解决方法是构建项目,然后重新添加表。我向微软报告了这个问题,在VS2010中得到了修复。
DBML显示不显示新的外键约束
请注意,主答案中给出的说明并不清楚。更新表
打开dbml设计面 选择所有带“右”的表->单击->选择全部或CTRLa CTRLx(削减) CTRLv(粘贴) 保存并重新构建解决方案。