Search code examples
nhibernatecastle-activerecord

How to do a JOIN between two tables using Castle ActiveRecord


I'm trying to perform a join in ActiveRecord using DetachedCriteria. I can't seem to make it work. There is no relationship defined inside the transfer objects. In SQL I should be able to do this but it seems that ActiveRecord wants to force me to define the relationship. What is the deal?

Can someone point me to some documentation?


Solution

  • If nothing else works, persistence always does. I worked out how to do it and it's very simple:

    DetachedCriteria SubmissionsQuery = DetachedCriteria.For<Submission>();
    
    SubmissionsQuery.Add(Restrictions.Eq("Kind", SubmissionKind.Question));
    SubmissionsQuery.SetProjection(Projections.Property("Id"));
    
    DetachedCriteria Filter = DetachedCriteria.For<Answers>();
    Filter.Add(Subqueries.PropertyIn("CommonId", SubmissionsQuery));
    Filter.SetFirstResult(Start);
    Filter.SetMaxResults (Size);
    
    ActiveRecordMediator<Answers>.FindAll(Filter);
    

    I hope the next person finds this useful.