I have the following objects
public class Parent {
int Id;
Object Obj1;
Object Obj2;
DateTime Date1;
IList<Child> Children;
}
public class Child {
int Id;
Parent Parent;
IList<GrandChild> GrandChildren;
}
public class GrandChild {
int Id;
Child Child;
DateTime Date2;
}
I need to limit the GrandChild list by Date2. I tried the following
Parent parentAlias = null;
Child childAlias = null;
GrandChild grandChildAlias = null;
ICriterion dateCriterion = Restrictions.Where<GrandChild>(
g => g.Date2.Date >= fromDate && g.Date2.Date <= toDate
);
var query = QueryOver.Of(() => parentAlias)
.Inner.JoinAlias(() => parentAlias.Children, () => childAlias)
.Inner.JoinAlias(() => childAlias.GrandChildren, () => grandChildAlias, dateCriterion)
.Where(p => p.Obj1.Id == param1 && p.Obj2.Id == param2 && p.Date1 == paramDate);
var result = query.GetExecutableQueryOver(session).SingleOrDefault();
However this does not filter the grand child collection.
Your input is greatly appreciated.
Thank you.