Use SQL query to populate property in nHibernate mapping file
- by brainimus
I have an object which contains a property that is the result of an SQL statement.  How do I add the SQL statement to my nHibernate mapping file?
Example Object:
public class Library{
    public int BookCount
    {
        get;
        set;
    }
}
Example Mapping File:
<hibernate-mapping>
    <class name="Library" table="Libraries">
        <property name="BookCount" type="int">  <- This is where I want the SQL query to populate the value. ->
    </class>
</hibernate-mapping>
Example SQL Query:
SELECT COUNT(*) FROM BOOKS WHERE BOOKS.LIBRARY_ID = LIBRARIES.ID