Hi Wolfgang,
Only that they are value objects in my domain not entities. They are quite literally just a string value. However the concept is used in more than one place in the domain. If I can't solve my querying issues I may be forced to create a separate table and map it as an entity in NHibernate.
The code you've suggested without the join doesn't work for me, but I have actually managed to resolve this particular issue. Kind of. My code now looks like this:
Code:
public IList<QuestionTemplate> GetQuestionTemplateByCriteria(string questionText, List<QuestionnaireDomain> domains,
List<QuestionnaireSubdomain> subdomains)
{
var domainNames = from domain in domains
select domain.DomainName;
var subdomainNames = from subdomain in subdomains
select subdomain.SubdomainName;
ISession session = _sessionManager.OpenSession();
StringBuilder queryText = new StringBuilder();
queryText.Append("select distinct qt from QuestionTemplate qt join qt.Domains d join qt.SubDomains s where qt.QuestionText like :questionText");
if (domains.Count > 0) queryText.Append(" AND d.DomainName in (:domainNames)");
if (subdomains.Count > 0) queryText.Append(" AND s.SubdomainName in (:subdomainNames)");
IQuery query = session.CreateQuery(queryText.ToString())
.SetString("questionText", String.Format("%{0}%", questionText))
.SetParameterList("domainNames", domainNames)
.SetParameterList("subdomainNames", subdomainNames);
return query.List<QuestionTemplate>();
}
So I can't query on the composite-element object itself, which I guess makes sense so instead I just query by the name property of each of them.
Thanks again for your help!