tags:

views:

454

answers:

2

Im using vs2008 and Im also using the autogenerated object model / entity classes from linq to sql (.dbml).

Is it possible / recommended to change the autogenerated .cs file. Eg change the behaviour of Equals (in the partical class Courses)?

I do know that Equals should be reflexive, symmetric, transitive, consistent and "Equals(null)== false "

+8  A: 

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.

Mehrdad Afshari
+1  A: 

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.

Rune Grimstad