Your way of validating input is very brittle. You are excepting any possible input (for the CustomerId in this case) and sanitize it when it is requested. This might work in this basic scenario, but in a lot of cases you can't sanitize the input. You are basically correcting the mistakes of the user and making assumptions of what he intended. How will you do that with an mail address? For instance, must the mail address 'stevenhotmail.com' be converted to '[email protected]' or to '[email protected]'. Besides this, there is also the possibility of a programming error. Would you want your program try to fix your own programming errors. This will give you headache. Or what will you do when two properties of the same entity have to be compared?
A better solution would be to allow the entity to become in an invalid state and check it's validity just before saving it to the database. When it’s state is invalid, don’t try to automatically correct the changes, but just throw an exception or communicate the errors back to the user.
There are multiple approaches of doing this. You can for instance implement an IsValid()
method on each entity or use a validation framework.