On a recent project, we are using Linq 2 SQL. I love Linq and Linq 2 SQL is pretty RAD as well. The problem is the designer. It sucks. Great idea, just poorly implemented.
We have run into some issues with using the designer that are very frusterating and through some digging and searching, we have come up with some ways around these issues. I wanted to share these with you to save you the time that I have already wasted.
The issues that we got around and I demonstrate are:
- Regeneration of the Linq 2 SQL designer code everytime causes the code you have placed in there to disappear.
-
Loss of the designer file when using statements are used within the .cs file.
Take a gander of this video which demostrates some of these work arounds. You may want to use full screen mode to view the code easily.

The "yourmodel.designer.cs" is specifically labelled as a "generated file - don't mess around in it" - so don't.
If it goes missing for some reason, you can easily re-create it - right-click on "YourModel.dbmx" and choose "Run Custom Tool" from the context menu - that's all there is (the file gets recreated).
Also - why don't you just create your own "blog.cs" and "post.cs" classes as partial classes to extend your classes in the model? Inside those cs files you create yourself, you can knock yourself out as you like (and put the using statements wherever you like.......)
Marc
Posted by: marc | May 21, 2009 at 05:20 AM
@Marc,
Thanks for your thoughtful comment. I appreciate the feedback. Here are my thoughts.
1. Yes, it does say that. I was just re-iterating that for users. In fact, that is one of my favorite comments "This code was generated by a tool"
2. That is a very good tip and will save time. I forgot about this menu option.
3. Yes, I think that needs to be done. I love LINQ, I just think that the designer needs a lot of work to work in real world scenarios. Hopefully it is greatly improved in VS 2010. The only issue with doing this yourself is taking the time to generate all the "help" code with it such as the INotifyPropertyChanged implementation. This will just take some time to generate once and reuse it all over the place.
Posted by: Jamie | May 22, 2009 at 10:18 AM