LINQ to SQL - formatting a string before saving?

I am trying to convert an existing (not LINQ to SQL) class to a LINQ to SQL entity class that has an existing property (db column), for example:

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

Is there a way to do this kind of processing for the value of a property of an object class before saving?

Should I use some kind of persistence event at the entity level where formatting can be done (if that works)?

I know that LINQ to SQL provides validation and creates partial On...Changing() methods that provide access to the new value by value (not by reference), but none of these methods provide a way to actually change / format the value while setting it.

Thank you for your help.

+2
source share
1 answer

How about using On ... Changed ()? It starts after changing the property value. There you can check its value and update it with FormatString.

+2
source

Source: https://habr.com/ru/post/1309411/


All Articles