Accepted answer

It's not suggested to change the generated file directly as it will be regenerated and overwrite your changes if you edit the DBML. The generated classes will be declared as partial so you can change them by creating another file and declaring a partial class with the same name and adding your changes there.


You can also add a common base class for your entities where you implement your custom code, but the Linq to Sql visual editor doesn't support it so you must edit your .dbml file manually.

In visual studio you can right-click the .dbml file in the solution explorer, select Open With, and then Xml Editor.

Now you can add the EntityBase attribute to the <Database> tag. The EntityBase attribute should contain the name of your common base class.

Finally you should right-click the .dbml file in the solution explorer and select Run Custom Tool. This will recreate your entity classes with the common base class.

Related Query

More Query from same tag