I am dealing with a database containing data with inconsistencies, such as a white start and back space.
In general, I see that many developers practice security coding, cutting off almost all the lines that come from the database, which may have been entered by the user at some point. In my oppinoin, it is better to do this formatting before the data is saved, so that it will be done only once, and then the data can be in a stable and reliable state. Unfortunately, this is not the case, but it leads me to the next best solution using the Trim method.
If I clip all the data as part of my data access level, then I don’t need to do security in the business objects of my domain. If instead I put responsibility for cropping in my business objects, for example, using a set of access elements to my C # properties, I should get the same results on the network, however cropping will work with all the values assigned to the properties of my business objects , and not just those that come from an inconsistent database.
I think this is a somewhat philosophical question that can determine the answer that I can ask, “ Should the domain level be responsible for the protective / forced formatting of the data? ” It would be reasonable to have a set of accessories for the PhoneNumber property on the business object accepting an unformatted or formatted string , and then tries to format it as necessary, or will this responsibility be transferred to the presentation and data access layers, leaving a more stringent level of the domain in the type of data that it will accept? I think this may be a more fundamental question.
Update: The following are a few links that I thought I should share with this topic.
Information Service Templates, Part 3: Data Cleansing Template
LINQ to SQL - formatting a string before saving?
How to trim values with Linq to Sql?