I have a field in my DTO that is an integer. In the database, there are some numbers stored as 1, 2, 101 etc. I want to make sure in the system they are always display as three digits, so 001, 002 for example. This is not working and I cannot figure out how to do it...any ideas out there? Here is the snippet from my DTO:
Private mArea As Integer
<Display(name:="Area")> _
<DisplayFormat(DataformatString:="{0:000}")> _
Public Property Area() As Integer
Get
Return mArea
End Get
Set(ByVal value As Integer)
mArea = value
End Set
End Property
The DisplayFormat attribute is just an information. Some UI Controls (for example some WPF controls) use it and respect it. It is just a hint. It changes not, how the integer is stored. An integer is stored as binary value. It has no inherent format or leading or trailing zeros (decimal has to some degree).
To reach your goal you have to format every output of the field you make in your application, or use UI Controls that respect the DisplayFormat attribute.