I have a number of associations within my LinqToSql designer file that I have h开发者_运维技巧ad 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?
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.
精彩评论