I'm stuck with a query I need to write.
Given the following model:
public class A : Entity<Guid>
{
public virtual IDictionary<B, C> C { get; set; }
}
public class B : Entity<Guid>
{
}
public class C : Entity<Guid>
{
public virtual int Data1 { get; set; }
public virtual ICollection<D> D { get; set; }
}
public class D : Entity<Guid>
{
public virtual int Data2 { get; set; }
}
I need to get a list of A
instances that have a D
containing some data for the specified B
(parameter)
In the object model, that would be:
listOfA.Where(a => a.C[b].D.Any(d => d.Data2 == 0))
But I wasn't able to write a working HQL.
I'm able to write something like the following, which filters on C.Data1:
from A a
where a.C[:b].Data1 = 0
But I'm unable to do anything with the elements of a.C[:b].D (I get various parsing exceptions)
Here are the mappings, in case you're interested (nothing special, generated by ConfORM):
<class name="A">
<id name="Id" type="Guid">
<generator class="guid.comb" />
</id>
<map name="C">
<key column="a_key" />
<map-key-many-to-many class="B" />
<one-to-many class="C" />
</map>
</class>
<class name="B">
<id name="Id" type="Guid">
<generator class="guid.comb" />
</id>
</class>
<class name="C">
<id name="Id" type="Guid">
<generator class="guid.comb" />
</id>
<property name="Data1" />
<bag name="D">
<key column="c_key" />
<one-to-many class="D" />
</bag>
</class>
<class name="D">
<id name="Id" type="Guid">
<generator class="guid.comb" />
</id>
<property name="Data2" />
</class>
Thanks!