开发者

Stop Visual Studio 2010 From Regenerating DBML When Target Framework is Changed

At work, we're trying to upgrade some existing VS2008 projects to work in VS2010 with .Net 4. The problem is, every time we change the target framework in a project that includes linq to sql dbml files, Visual Studio then goes and regenerates the code for every dbml 开发者_Python百科file. This is causing us thousands of errors due to properties that were removed from the partial classes that we have to go manually remove again.

Is there a way to stop Visual Studio from doing this?


This sounds like something I used to run into. Tons of pain taught me to never edit the DBML files generated by Visual Studio. The files get re-generated so often that I saw that as something that would quickly become a maintenance nightmare.

Instead, you should be taking advantage of partial classes to move your custom logic into your own partial class files, so that those changes remain intact when the DBML gets re-generated.

If you're "removing properties" I assume that this is being done because there are certain database fields that you don't want represented. You can use Data Annotations to hide fields, make them read-only, etc. I can't seem to find as lot of walk-throughs, and I learned basically by trial and error, but you can start here: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx

Following those guidelines will insulate you from having to modify the DBML files when the Target Framework is changed, or any other scenario where the DBML needs to get re-generated, such as when a change to the source database is made and the model needs to be refreshed.

Edit I found a link here: http://simon-holman.net/2010/03/using-data-annotations-with-partial-classes-and-linq-to-sql/

using this Google search, which turns up other promising links: http://www.google.com/search?q=DataAnnotations+to+customize+Linq+to+SQL&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜