NHibernate: best way to map to DateTime value stored in non-standard way

I am just starting out with NHibernate (15th time it will look like) and I have the following problem.

In the following table:

Table Facility
Column FACILITY_ID integer
Column NAME varchar2(50)
Column MONTH varchar2(5)

      

For whatever reason, the month is a string instead of the native Date type and looks like this:

"200811" represents 11/01/2008
"200307" represents 07/01/2003
you get the idea

      

I would like to map it to the following class

public class Facility {
  int Id {get; set;}
  string Name {get; set;}
  DateTime Month {get; set;}
}

      

I would like to map the MONTH column to the Month property, but don't know how to approach the situation. Obviously I could have a protected property string MonthString and have a Month property in Parse, but that doesn't seem good. Is there a better solution?

0


source to share


2 answers


I think the best solution might be to use a custom value type .



+1


source


If you cannot change the database schema, the answer is IUserType

. Here's a good entry .



There are many extension points that can help you solve complex problems in NHibernate. The most useful extension point is IUserType.

0


source







All Articles