如何重新生成(更新)LINQ to SQL DataContext?
我在 WPF 项目中使用 LINQ to SQL。我对数据库做了一些小更改(更改了字段的数据类型,其中不包含数据)。
现在我想重新生成(刷新)该项目的 LINQ to SQL DataContext(我使用 VS 2008)。我尝试右键单击解决方案资源管理器中的 .dbml 项目并选择“刷新”,但没有任何反应。
如何更新 Visual Studio 2008 WPF 项目中的 DataContext?
I use LINQ to SQL in a WPF project. I have made small changes in the database (changed datatype of the fields, which contain no data).
Now I want to regenerate (refresh) the LINQ to SQL DataContext of this project (I use VS 2008). I try to right-click on .dbml item in my Solution Explorer and choose "Refresh", but nothing happens.
How could I update the DataContext in a Visual Studio 2008 WPF project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在不借助某些第三方工具的情况下,最简单的方法就是从设计器中删除修改后的表,然后将它们从服务器资源管理器中拖回。
不幸的是,如果您在 L2S 设计器中进行了任何手动修改,它们将不会被保留,并且您必须再次手动进行更改。
huagati有一个工具,声称可以刷新更改,但我自己没有尝试过。
Without resorting to some 3rd party tools, the easiest way is just to delete the modified tables from the designer and drag them back in from Server Explorer.
Unfortunately, if you've made any manual modifications in the L2S designer they wont be preserved and you'll have to manually make the changes again.
huagati has a tool that claims to be able to refresh changes but I haven't tried it myself.
正如其他答案所述,只能通过删除并重新添加表来完成。但是,如果您稍后迁移到实体框架,则可以完全执行您正在寻找的操作(上下文[右键单击]菜单中将有一个“从数据库更新模型”选项)。
As other answers have stated it can only be done by deleting and re-adding the table. If you later move to Entity Framework however there is the ability to do exactly what you are looking for (there will be an "Update Model from Database" option in the context [right click] menu).
有一个命令行工具
sqlmetal.exe
可以自动生成.dbml
文件。SQLMetalplus 是一个向 Visual Studio 添加扩展的项目,以便有一个
Create/Refresh
https://github.com/thedemz/dotnet-sqlmetal-plus
There is the command line tool
sqlmetal.exe
that autogenerates the.dbml
file.SQLMetalplus is a project that adds an extension to Visual Studio so that there is an
Create/Refresh
https://github.com/thedemz/dotnet-sqlmetal-plus