User-defined types
For every property on the entity that you map, NHibernate uses its own defaults to determine the right database column type. On most occasions, this just works. If it does not and you need minor changes to type, for example, instead of Int32
you want Int64
, you can do it via entity mapping. But if you need to map a database column to a property of a completely unrelated type, then you can define your own type for NHibernate to work with. This obviously assumes that your code knows both the type in the database and the type in the code. Your code also should know how these two types convert from each other.
Consider for example, you are working on a legacy database situation. You have got an Employee
table which has a NVARCHAR(1)
type of column named IsEmployed
. A value of Y
in this column means that the employee is still part of the organization. A value of N
in this column means that the employee has left the organization. Now, while building the domain model for this...