I have a class
public class Site {
public DateTime SiteMonth {get; set;}
}
in the database the SiteMonth is represented as an integer in yyyymm format.
Is there a way to map this in NHibernate without introducing a new property on my Site class?
From stackoverflow
-
Yes - make a simple
IUserTypethat maps between your integer format and a DateTime. Then set thetypeattribute on thepropertyelement to theAssemblyQualifiedNameof that user type.Ayende has an example on how to implement a user type.
Oh yeah, and if you are using Fluent NHibernate to do your mappings, you can do it like this:
Map(d => d.MyFunkyWeirdLegacyDateTime) .SetAttribute("type", typeof(MyCustomDateTime).AssemblyQualifiedName);James Gregory : `CustomTypeIs()` is the preferred method, instead of `SetAttribute`. mookid8000 : Ah, thanks for pointing that out! Fluent NHibernate is smashing, by the way :-) -
I was just in the Fluent NHibernate Wiki and came across this, which is in the AutoMapping conventions, but in the Fluent Mapping Conventions section it mentioned that the AutoMapping Conventions will work for Fluent Mapping as well.
0 comments:
Post a Comment