Another NHibernate JOIN problem.
I\'m trying to join two different properties from one table by different two keys. But I can\'t get the second JOIN property.
<Apparently, this cannot be done at the moment with NHibenate mappings. The closest solution, suggested by Spencer Ruport, is to create a view and map the object to it.
I was lurking thru the internet all day long to find solution to same problem. What I found is thread on hibernate board. I took solution from Ashkan Aryan . So if anyone else gets headaches about solution and don't want to use views I will post my code which I am using now.
I have to use from 1 to 12 joins on same table so creating views is to much confusing.
private void addParagraphsQuery(DetachedCriteria sourceQuery, List<ParagraphContentArgument> paragraphsArguments)
{
DetachedCriteria dc;
Conjunction conjunction = Restrictions.Conjunction();
string alias = string.Empty;
if (paragraphsArguments != null && paragraphsArguments.Count > 0)
{
for (int i = 0; i < paragraphsArguments.Count; i++)
{
alias = "p" + i.ToString();
dc = DetachedCriteria.For<Document>().SetProjection(Projections.Id());
dc.CreateAlias("paragraphList", alias);
dc.Add(Restrictions.Eq(alias + ".paragraphSectionTemplate", paragraphsArguments[i].ParagraphTemplate));
dc.Add(Restrictions.Like(alias + ".content", paragraphsArguments[i].Argument, MatchMode.Anywhere));
conjunction.Add(Property.ForName("id").In(dc));
}
}
sourceQuery.Add(conjunction);
}
Regards,
Mariusz