Question: 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...?

Answer: 
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.
I've just encountered the same issue, Marc's suggestion got me past the custom tool error. But the .designer.cs file was still getting deleted.

I noticed that if I change the DBML and close the DBML (it asks to save, and I choose yes), it will delete the designer.cs file. If I don't close the DBML, but instead tell it to build right now, it seems to regenerate the .designer.cs file and compile without issues.

I can then close the DBML and everything is fine.

Very odd interactions. A coworker also encountered similar issues to what Shaul was reporting above.