2

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.