tags:

views:

25

answers:

1

I have a number of associations within my LinqToSql designer file that I have had to add the attribute DeleteOnNull to. However if I change anything through the GUI then the designer file is re-created and I lose my DeleteOnNull attributes.

Is there anyway I can stop this happening?

+1  A: 

To add a DeleteOnNull attribute, you'll have to edit your .dbml file directly. To do this, navigate to it with Windows Explorer and open it in Notepad (or whatever - just not Visual Studio). Then edit the association and add the DeleteOnNull attribute like below. Then, the next time you open the dbml designer in Visual Studio, it should respect your changes, and include your attribute in the .Designer.cs file.

.dbml direct (Notepad) edit:

  <Association Name="Employee_EmployeeAddress" Member="Employee" ThisKey="EmployeeID" Type="Employee" IsForeignKey="true" DeleteOnNull="true" />

Attribute generated in .Designer.cs file after you do a save on the dbml designer in Visual Studio (which forces the .Designer.cs file to be regenerated):

[Association(Name="Employee_EmployeeAddress", Storage="_Employee", ThisKey="EmployeeID", IsForeignKey=true, DeleteOnNull=true)]

Hope that helps!

And here is a related discussion, FYI.

shaunmartin