NHibernate property mapping: columns and formula

npeBeg picture npeBeg · Nov 26, 2009 · Viewed 8.9k times · Source

When i map columns from the inspected table, i do this:

<property name="InstanceName" type="MyNameUserType, MyApp.MyNamespace">
   <column name="Name"/>
   <column name="Name2"/>
</property>

How can I make property mapping initialize a UserType with data retrieved by the formula's sql query?

<property name="InstanceName" type="MyNameUserType, MyApp.MyNamespace" formula="(...)"/>

fails with an exception "wrong number of columns".

Thanks in advance!

Answer

Michael Gattuso picture Michael Gattuso · Nov 27, 2009

MyUserNameType should be a class level mapping so that you can map the result of the SQL function to a class. See these two posts for some possible help:

  1. Class and SQL Function example: http://thoughtspam.spaces.live.com/blog/cns!253515AE06513617!478.entry

  2. NHibernate Mapping with formula mapping example: http://thoughtspam.spaces.live.com/blog/cns!253515AE06513617!477.entry