9

Every time that I change a value in the designer after saving it, the .designer.cs file will be deleted.

Can anyone tell me how can I fix this problem?

Eddie
  • 53,828
  • 22
  • 125
  • 145
mrtaikandi
  • 6,753
  • 16
  • 62
  • 93

3 Answers3

20

Move using directives in your DataContext.cs and DataContext.designer.cs files into the namespace scope.

gius
  • 9,289
  • 3
  • 33
  • 62
11

The *.designer.cs files are completely generated by designer. You should not write any your own code into this file. The classes and/or methods are partial, so you can extend/change the behaviour in the separate file.

TcKs
  • 25,849
  • 11
  • 66
  • 104
  • This is not entirely accurate. There is a region in the designer which is auto generated "#region Windows Form Designer generated code" - this also has the comment telling you not to modify. You can however modify the content of the Dispose method, as an example and this won't get overwritten by the designer. – russelrillema Sep 05 '22 at 10:35
7

Don't place your own code in the designer file, instead use a separate file leveraging the partial classes concept.

FlySwat
  • 172,459
  • 74
  • 246
  • 311
  • I thinks this should solve the problem but I have 2 other dbml files which I wrote my code in their code files and there is no problem but since yesterday every new dbml files has it. – mrtaikandi Nov 15 '08 at 13:51