Use SQL query to populate property in nHibernate mapping file

Posted by brainimus on Stack Overflow See other posts from Stack Overflow or by brainimus
Published on 2010-06-17T15:01:14Z Indexed on 2010/06/17 15:13 UTC
Read the original article Hit count: 187

Filed under:

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

© Stack Overflow or respective owner

Related posts about nhibernate