Q:

My O/R Designer keeps deleting the designer.cs file!

I have a weird problem that sometimes when I make a change to a Linq object using the O/R designer (usually by adding a field that I've added in the DB), when I save the project, the designer.cs file gets deleted!
Fortunately I have my source control to fall back on; I undelete the file and back out the changes to the csproj file.  But this is really annoying, and doesn't appear to have any good reason (the fact that my project contains about 100 objects is not an excuse).
Has anyone else had this trouble?  Any idea what could be causing this to happen?
Edit - additional info - my DataContext class is set up with a custom base class.  D'ya think this might have something to do with it...?

A:

Have you added a partial class to add functionality (etc) to the generated classes? If so - odd though it sounds, the position of any using statements in your partial class file can actually be a problem that breaks code generation. Try moving them inside the namespace.
No, I am not kidding.
The error message in this case is "The custom tool 'MSLinqToSQLGenerator' failed. Unspecified error". Changing from:
using System;
namespace MyNamespace {
    partial class MyDataContext {}
}

to:
namespace MyNamespace {
    using System; 
    partial class MyDataContext {}
}

fixes it. Freaky bug.

A:

I have a similar problem with the DataSet designer, when working on a big DataSet. You don't need to undelete the file with your source control system : just saving your work in the designer should regenerate the .designer.cs file. You can also right-click the file and select "Run custom tool", which has the same effect.

A:

It may be too early to tell, because the behavior is erratic, but it seems to me that if I keep the designer.cs file open in the IDE editor when I make changes on the .dbml file, then it doesn't get removed when I hit "Save".  
I've tried that a few times, and it seems to work... No good explanation why that should be, but then the problem is not one that can be subjected to logical scrutiny, either...
Later...
Having tried this out a few times, I can say that this consistently works, so I'm marking this as the answer!
Thanks to all for your help!

