Another important difference between them arises when using LINQ-to-SQL and the generated datacontext classes. For example, the Northwind sample database; initially, you get:
Northwind.dbml
Northwind.dbml.layout
Northwind.designer.cs
If you now want to extend the partial classes by adding your own Northwind.cs
, you get
Northwind.dbml
Northwind.dbml.layout
Northwind.designer.cs
Northwind.cs
Amusingly, there is a bug in the code-generator (MSLinqToSQLGenerator
) - which means that if the using
directives are outside the namespace (like they are by default), it breaks - with the message:
The custom tool 'MSLinqToSQLGenerator' failed. Unspecified error
And the Northwind.designer.cs
file gets deleted. No more data-context!
However, if you move the using
directives inside the namespace (and re-run the custom tool - right click in solution explorer), it works correctly.
So: this isn't a language detail - it is simply a bug in the code generator; but there is a pretty big difference between "works correctly" and the generated code getting deleted...
Note you can also fix this simply by calling your file something different - such as NorthwindExtras.cs
.
Freaky.