views:

302

answers:

1

I'm trying to convert an existing (non-LINQ to SQL) class into a LINQ to SQL entity class which has an existing (db column) property like:

public string MyString
{
    get { return myString; }
    set { myString = FormatMyString(value); }
}

Is there a way to do this sort of processing on the value of entity class property before saving?

Should I use some sort of an entity-level saving event in which to do my formatting (if that will even work)?

I know LINQ to SQL provides validation and there are generated On...Changing() partial methods which provide access to the new value, by value (not by ref), but none of those methods seem to provide a way to actually modify/format the value while it is being set.

Thank you for your help.

+2  A: 

What about using On...Changed()? It fires after the property value has changed. There you can check its value and update it using the FormatString.

amrinder
Sorry for the late follow-up (got sidetracked). Yes, this is the method I used, thanks! What I hadn't thought of (since I'm still a L2S noob), is that in On...Changed(), you have access to the private member variable, named "_PropertyName" by the entity designer, which you can format and change without recursively triggering the OnChanging/OnChanging events. Thanks again.
shaunmartin