My situation is I'm working with a legacy database that has two traits that are common for most of the code - there are many values saved with fixed length that are padded with leading zeros, and also fixed length with trailing white space at the end. Very annoying to deal with, so I'm trying to figure out what the cleanest approach for formatting these values would be.
My main focus right now is on formatting the view models / dtos. I'm just querying the database with Dapper via queries or stored procedures, which get mapped to my DTO class, which gets served as Json through my webapi.
Right now this is what a lot of my model properties end up looking like:
public string PurchaseOrderNumber
{
get => _purchaseOrderNumber.TrimStart('0');
set => _purchaseOrderNumber = value;
}
This just ends up being repeated everywhere. It would be nice to be able to do something like this:
[TrimZeros]
public string SupplierName { get; set; }
I could aslo make a function that just does this in SQL, then make this a responsibility of all my sql queries/ stored procedures. This works when I'm using something light like Dapper, but not so much when I'm using Entity Framework.
Any recommendations on how to approach this?