Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Linq2SQL classes are <em>partial classes</em>, which means you can easily extend them by adding your own separate file and declaring another part of the partial class in there.</p> <p>In that file, you can customize the class as needed - and since it's a separate file, the code generation will not overwrite it.</p> <p>If you look at e.g. the "Contact" class in the AdventureWorks database, Linq2SQL will generate this in your AdventureWorks.designer.cs file:</p> <pre><code>[Table(Name="Person.Contact")] public partial class Contact : INotifyPropertyChanging, INotifyPropertyChanged { </code></pre> <p>Now you can add a "Contact.cs" file to your project, and extend that partial class, e.g. by introducing a new property "DisplayName":</p> <pre><code>public partial class Contact { public string DisplayName { get { return string.Format("{0} {1}", FirstName, LastName); } } } </code></pre> <p>At compile time, these two parts of the class are merged together.</p> <p>The other part are the partial methods - methods that are available for you to implement, but if they're not implemented, calls to them are being optimized out by the compiler.</p> <p>For each object class in Linq2SQL, a whole slew of partial methods (a new feature in .NET 3.0) are being created - up to you to implement those!</p> <pre><code>partial void InsertContact(Contact instance); partial void UpdateContact(Contact instance); partial void DeleteContact(Contact instance); partial void OnLoaded(); partial void OnValidate(System.Data.Linq.ChangeAction action); partial void OnCreated(); partial void OnFirstNameChanging(string value); partial void OnFirstNameChanged(); partial void OnLastNameChanging(string value); partial void OnLastNameChanged(); </code></pre> <p>Plenty of extension points!</p> <p>Marc</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload