我如何更新一个Linq到SQL .dbml文件?
当前回答
在存储过程更新的情况下,应该从.dbml文件中删除它,然后重新插入它。但是如果存储过程有两条路径(例如:if something;显示一些列;否则显示一些其他列),确保两个路径有相同的列别名!!否则只有第一个路径列存在。
其他回答
在存储过程更新的情况下,应该从.dbml文件中删除它,然后重新插入它。但是如果存储过程有两条路径(例如:if something;显示一些列;否则显示一些其他列),确保两个路径有相同的列别名!!否则只有第一个路径列存在。
下面是对我有效的完整的分步方法,用于更新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!).
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
只是为了记录
你也可以看看基于CodeSmith的PLINQO代码生成模板集,它允许你为Linq-to-SQL做很多漂亮的事情:
为每个类生成一个文件(而不是一个巨大的文件) 根据需要更新您的模型 更多特性
查看PLINQO网站http://www.plinqo.com,并观看介绍视频。
我知道的第二个工具是Huagati DBML/EDMX工具,它允许更新DBML (Linq-to-SQL)和EDMX(实体框架)映射文件,以及更多(如命名约定等)。
Marc