LINQ to SQL - Format a string before saving?
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.
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.
精彩评论