views:

543

answers:

1

When I generate entity classes using LINQ to SQL I get what I want but I get also a bunch of other Extensibility Methods Definitions.

For Example for myField (TEXT) I get:

   partial void OnMyFieldChanging(string value);
   partial void OnMyFieldChanged();

What's a common use for the extensibility methods above?

+1  A: 

The most examples I have seen for overriding these methods is for validation use.

partial void OnMyFieldChanging(string value)
{
  if(value == valid)
     continue;
  else
    throw new Exception();
}

You can override these methods directly for each property or also override OnValidate() for the whole object

TT
looks like a good place to plug a CustomValidator in there - doesn't look intuitive 'cause usually (without linQ) I validate stuff before creating the object that models entities
JohnIdol