Ever since I started using an ORM for my day to day data access. I've started to think about how much I should rely formatting functions for my columns. By formatting functions, I mean such things as Oracle's decode()
, instr()
and initcap()
.
Example
Say I'm selecting this column using formatting in Oracle.
(to_number(to_char(to_date('1', 'J') + (EndTime - StartTime), 'J') - 1) * 24)
+ (to_char(to_date('00', 'HH24') + (EndTime - EndTime), 'HH24'))
|| ':' ||
to_char(to_date('00', 'MI') + (EndTime - StartTime), 'MI')
as duration_time
It's not very pretty, I know. Since formatting something like that using an ORM (I'm using NHibernate) is probably a waste of time. I was thinking I could simply allow me DTO to take care of that formatting. I could use something like this in my C# set
property.
public TimeSpan DurationTimeSpan
{
get
{
return EndTime.Subtract(StartTime);
}
}
So my question is, should I let me DTO object take care of such formatting? Or is a DTO object not supposed to be responsible for such thing? Personally, it looks like it might be far cleaner to let me DTO's set
properties to do such formatting. From the looks of it, most formatting can probably be achieved with very simple C#.