Visual Studio 2008 SP1 Deletes LINQ to SQL designer files

Posted 09 February 2009, 11:30 | by | Perma-link

We had the following issue: We'd gone back to an old .dbml file, and added a new table on to the design surface. Visual Studio proceeded to check out the project file, and delete the .designer.cs file from the system - which we failed to notice initially, as it's a nested file. What we did notice however was that nothing would compile, especially not our DAL, as the partial class within the data context contained lots of red squiggly lines and complained that most of our data objects no longer existed.

Looks like I'm not the only one seeing this, and MS fixed it last month, but I'm not sure when the fix is coming out.

Thankfully, there is a work around, and it seemed to work quite well for us:

In your partial class, move any using statements inside the namespace:

namespace DataContexts {
  using System.Collections.Generic;
  using System.Linq;
  partial class ConfigDataContext
  {
    [...]
  }
}

Then right-click on the .dbml file in Solution explorer, and select "Run Custom Tool". This will then regenerate the designer files, and your code will now compile.

Filed under: Fixes, LINQ