I am trying to create an association to load a list of parent objects based on a child objects date field. I only want parent objects where the date is >= a given date.
The problem is, when I use either today's date or the day before, it returns the correct children. But if I use a date further back in time, like 11-2-2010, it is including children that have a date < 11-2-2010.
Here is the code:
public IList<Parent> GetByDate(string parentId, DateTime date) {
IList<Parent> list = null;
using (ISession session = SessionFactory.OpenSession()) {
list = session.CreateCriteria(typeof(Parent))
.Add(Expression.Eq("parent_id", parentId))
.CreateCriteria("children")
.Add(Expression.Gt("end_date", date)).List<Parent>();
}
return list;
}
and the mapping for Parent:
<id name="id">
<generator class="native"/>
</id>
<property name="parent_id" />
<bag name="children" lazy="false">
<key column="parent_id" />
<one-to-many class="Child" />
</bag>
Thanks in advance!