开发者

How to regenerate (update) LINQ to SQL 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 LIN开发者_开发技巧Q 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?


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).


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

How to regenerate (update) LINQ to SQL DataContext?

https://github.com/thedemz/dotnet-sqlmetal-plus


  1. Delete the Designer class file
  2. Redrag the tables from Server Explorer to the designer.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜