我如何更新一个Linq到SQL .dbml文件?


当前回答

有三种方法可以使模型保持同步。

Delete the modified tables from the designer, and drag them back onto the designer surface from the Database Explorer. I have found that, for this to work reliably, you have to: a. Refresh the database schema in the Database Explorer (right-click, refresh) b. Save the designer after deleting the tables c. Save again after dragging the tables back. Note though that if you have modified any properties (for instance, turning off the child property of an association), this will obviously lose those modifications — you'll have to make them again. Use SQLMetal to regenerate the schema from your database. I have seen a number of blog posts that show how to script this. Make changes directly in the Properties pane of the DBML. This works for simple changes, like allowing nulls on a field.

DBML设计器在Visual Studio 2015、2017或2019中默认不安装。你必须关闭VS,启动VS安装程序并修改你的安装。LINQ to SQL工具是必须安装的特性。对于VS 2017/2019,你可以在单独组件>代码工具下找到它。

其他回答

使用Visual Studio 2019在图形设计器中打开DBML文件更新DBML文件。

不工作时:https://developercommunity.visualstudio.com/t/dbml-files-not-opening-in-graphic-designer-in-vs-2/1659675

只是为了记录

你也可以看看基于CodeSmith的PLINQO代码生成模板集,它允许你为Linq-to-SQL做很多漂亮的事情:

为每个类生成一个文件(而不是一个巨大的文件) 根据需要更新您的模型 更多特性

查看PLINQO网站http://www.plinqo.com,并观看介绍视频。

我知道的第二个工具是Huagati DBML/EDMX工具,它允许更新DBML (Linq-to-SQL)和EDMX(实体框架)映射文件,以及更多(如命名约定等)。

Marc

在存储过程更新的情况下,应该从.dbml文件中删除它,然后重新插入它。但是如果存储过程有两条路径(例如:if something;显示一些列;否则显示一些其他列),确保两个路径有相同的列别名!!否则只有第一个路径列存在。

有三种方法可以使模型保持同步。

Delete the modified tables from the designer, and drag them back onto the designer surface from the Database Explorer. I have found that, for this to work reliably, you have to: a. Refresh the database schema in the Database Explorer (right-click, refresh) b. Save the designer after deleting the tables c. Save again after dragging the tables back. Note though that if you have modified any properties (for instance, turning off the child property of an association), this will obviously lose those modifications — you'll have to make them again. Use SQLMetal to regenerate the schema from your database. I have seen a number of blog posts that show how to script this. Make changes directly in the Properties pane of the DBML. This works for simple changes, like allowing nulls on a field.

DBML设计器在Visual Studio 2015、2017或2019中默认不安装。你必须关闭VS,启动VS安装程序并修改你的安装。LINQ to SQL工具是必须安装的特性。对于VS 2017/2019,你可以在单独组件>代码工具下找到它。

我建议使用VS2008内置的可视化设计器,因为更新dbml也会更新为您生成的代码。在可视化设计器之外修改dbml将导致底层代码不同步。