The trick here is to use partial class; create a new .cs file and in the same namespace add a new class with a name for your type:
namespace My.Data.Namespace {
partial class Employee {
public string Foo {
get {return Forename + " " + Surname; }
}
}
}
This is combined with the original (generated) class file. This is a general approach for adding additional functions to generated objects (including data context). You can also look at "partial methods" since a number of private methods are defined and used by LINQ-to-SQL.
One warning: if your dbml is called MySystem.dbml, then avoid creating the file MySystem.cs(presumably for your partial classes); There is an error in the code generator that could lead to a crash. Just call it something else.
source
share