NHibernate Polymorphic Query on a Collection

criteria, hibernate, hql, nhibernate

Solution

I'm not sure about the Criteria API, but HQL seems to handle polymorphic queries quite well, even when searching on a property that only exists in a specific sub-class. I would expect the following to work:

from Workflow w join w.Log l where l.class = Note and l.Content like '%keyword%'

Problem

I'm trying to write a query in NHibernate. I don't really care if I use the Criteria API or HQL, I just can't figure out how to write the query. Here's my model: ``` public class LogEntry { public DateTime TimeCreated { get; set; } } public class Note : LogEntry { public string Content { get; set; } } public class Workflow { public IList<LogEntry> Log { get; set; } } ``` I want the query to return all Workflows that which contain a Note with specific words in the Content of the note. In pseudo-SQL, I'd write this like: ``` select w.* from Workflow w join w.Log l where l is class:Note where (Note)l.Content like '%keyword%' ```

Original source