I want to have a 'virtual' (not there, not to be confused with the virtual keyword) field in a nhibernate class.
I have a securities table and I want to have a 'virtual' field that uses another field to return a flag.
I have added a calculated field in the db_securities table nhibernate class:
public class DB_Securities
{
private string cusip;
private string securityDescription;
...
private string classCode;
...
private String isSweepAccount;
...
public virtual string ClassCode
{
get { return classCode; }
set { classCode = value; }
}
...
public virtual String IsSweepAccount
{
get
{
isSweepAccount = (classCode > 20 && ClassCode < 25)?"Y":"N" ;
return isSweepAccount;
}
set { isSweepAccount = value; }
}
}
I have the DB_Securities.hbm.xml with
<class name="<namespace>.DB_Securities, <assembly>" lazy="true" table="Securities">
<id name="Cusip" type="String" length="9">
<generator class="assigned" />
</id>
<property name="SecurityDescription" type="String" length="36"/>
...
<property name="ClassCode" type="String" length="3"/>
...
<property name="IsSweepAccount" type="String" update="false" insert="false"/>
I think this should allow me to access field IsSweepAccount as though it was in the table but I get:
Inner Exception = Invalid column name 'IsSweepAccount'.
and the SQL showing that it is creating a select and referencing that column name, which should be alright.
I did this very thing in java/hibernate about a year ago succesfully. This is my first try at the same thing in nhibernate.
What am I missing?